-
Notifications
You must be signed in to change notification settings - Fork 1
linting (automatic and manual) + pre-commit #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
c99d67d
a6ff16d
4828684
cfcdefa
e5ca4e2
b2274d4
61fcdeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,4 +26,4 @@ | |
| *.pyo | ||
| *.pyd | ||
| README.md | ||
| .admin/tokens | ||
| .admin/tokens | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,4 +114,4 @@ | |
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
|
|
||
| from firebase_admin import auth | ||
|
|
||
|
|
||
| def authenticate(request): | ||
| """ Identify the user's Firebase account using an ID token. """ | ||
| """Identify the user's Firebase account using an ID token.""" | ||
| authorization = request.headers["Authorization"] | ||
| token = authorization.split(' ')[1] | ||
| token = authorization.split(" ")[1] | ||
| claims = auth.verify_id_token(token) | ||
| uid = claims['uid'] | ||
| request.session['uid'] = uid # Save user's custom claims in a session? | ||
| return claims | ||
| uid = claims["uid"] | ||
| request.session["uid"] = uid # Save user's custom claims in a session? | ||
| return claims |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,30 @@ | ||
| from rest_framework.decorators import api_view | ||
| from rest_framework.response import Response | ||
|
|
||
| @api_view(['GET']) | ||
|
|
||
| @api_view(["GET"]) | ||
| def scholars(request, format=None): | ||
| """Get information about scholars.""" | ||
|
|
||
| if request.method == 'GET': | ||
| author = request.query_params.get('q', None) | ||
| if request.method == "GET": | ||
| author = request.query_params.get("q", None) | ||
| if author: | ||
| from scholarly import scholarly | ||
|
|
||
| search_query = scholarly.search_author(author) | ||
| author_source = next(search_query) | ||
| author_data = { | ||
| 'author': author, | ||
| 'affiliation': author_source['affiliation'], | ||
| 'cited_by': author_source['citedby'], | ||
| 'email_domain': author_source['email_domain'], | ||
| 'interests': author_source['interests'], | ||
| 'photo_url': author_source['url_picture'], | ||
| } | ||
| "author": author, | ||
| "affiliation": author_source["affiliation"], | ||
| "cited_by": author_source["citedby"], | ||
| "email_domain": author_source["email_domain"], | ||
| "interests": author_source["interests"], | ||
| "photo_url": author_source["url_picture"], | ||
| } | ||
| return Response(author_data, content_type="application/json") | ||
|
|
||
| # Return an error if no author is specified. | ||
| error_message = 'Author not found in request. Specify ?q={url_encoded_author_name}' | ||
| return Response({ "error": error_message}, content_type="application/json") | ||
| error_message = ( | ||
| "Author not found in request. Specify ?q={url_encoded_author_name}" | ||
| ) | ||
| return Response({"error": error_message}, content_type="application/json") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,39 +7,41 @@ | |
| from .auth import authenticate | ||
|
|
||
|
|
||
| @api_view(['GET']) | ||
| @api_view(["GET"]) | ||
| def lab(request, format=None): | ||
| """Get or update information about a lab.""" | ||
|
|
||
| # Query labs. | ||
| if request.method == 'GET': | ||
| if request.method == "GET": | ||
| limit = request.query_params.get("limit", None) | ||
| order_by = request.query_params.get("order_by", "state") | ||
| # TODO: Get any filters from dict(request.query_params) | ||
| labs = get_collection('labs', order_by=order_by, limit=limit, filters=[]) | ||
| return Response({ "data": labs}, content_type="application/json") | ||
| labs = get_collection("labs", order_by=order_by, limit=limit, filters=[]) | ||
| return Response({"data": labs}, content_type="application/json") | ||
|
|
||
|
|
||
| @api_view(['GET', 'POST']) | ||
| @api_view(["GET", "POST"]) | ||
| def labs(request, format=None): | ||
| """Get or update information about labs.""" | ||
|
|
||
| # Query labs. | ||
| if request.method == 'GET': | ||
| if request.method == "GET": | ||
| limit = request.query_params.get("limit", None) | ||
| order_by = request.query_params.get("order_by", "state") | ||
| # TODO: Get any filters from dict(request.query_params) | ||
| labs = get_collection('labs', order_by=order_by, limit=limit, filters=[]) | ||
| return Response({ "data": labs}, content_type="application/json") | ||
| labs = get_collection("labs", order_by=order_by, limit=limit, filters=[]) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usage on line 90 uses double quotes, assuming that was the intent. leaving this |
||
| return Response({"data": labs}, content_type="application/json") | ||
|
|
||
| # Update a lab given a valid Firebase token. | ||
| elif request.method == 'POST': | ||
| elif request.method == "POST": | ||
|
|
||
| # Check token. | ||
| try: | ||
| claims = authenticate(request) | ||
| except: | ||
| return Response({"error": "Could not authenticate."}, status=status.HTTP_400_BAD_REQUEST) | ||
| except Exception: # TODO: what is the correct exception? | ||
| return Response( | ||
| {"error": "Could not authenticate."}, status=status.HTTP_400_BAD_REQUEST | ||
| ) | ||
|
|
||
| # Get the posted lab data. | ||
| lab = request.data | ||
|
|
@@ -56,7 +58,7 @@ def labs(request, format=None): | |
| before = existing_data[key] | ||
| if before != after: | ||
| changes.append({"key": key, "before": before, "after": after}) | ||
|
|
||
| # Get a timestamp. | ||
| timestamp = datetime.now().isoformat() | ||
| lab["updated_at"] = timestamp | ||
|
|
@@ -80,31 +82,29 @@ def labs(request, format=None): | |
| return Response(log_entry, status=status.HTTP_201_CREATED) | ||
|
|
||
|
|
||
| @api_view(['GET', 'POST']) | ||
| @api_view(["GET", "POST"]) | ||
| def lab_logs(request, org_id, format=None): | ||
| """Get or create lab logs.""" | ||
|
|
||
| if request.method == 'GET': | ||
| if request.method == "GET": | ||
| data = get_collection(f"labs/{org_id}/logs") | ||
| return Response({ "data": data}, content_type="application/json") | ||
|
|
||
| elif request.method == 'POST': | ||
| # TODO: Create a log. | ||
| return Response({ "data": "Under construction"}, content_type="application/json") | ||
| return Response({"data": data}, content_type="application/json") | ||
|
|
||
| elif request.method == "POST": | ||
| # TODO: Create a log. | ||
| return Response({"data": "Under construction"}, content_type="application/json") | ||
|
|
||
|
|
||
| @api_view(['GET', 'POST']) | ||
| @api_view(["GET", "POST"]) | ||
| def lab_analyses(request, org_id, format=None): | ||
| """ | ||
| Get or update (TODO) lab analyses. | ||
| """ | ||
|
|
||
| if request.method == 'GET': | ||
| if request.method == "GET": | ||
| data = get_collection(f"labs/{org_id}/analyses") | ||
| return Response({ "data": data}, content_type="application/json") | ||
|
|
||
| elif request.method == 'POST': | ||
| # TODO: Create an analysis. | ||
| return Response({ "data": "Under construction"}, content_type="application/json") | ||
| return Response({"data": data}, content_type="application/json") | ||
|
|
||
| elif request.method == "POST": | ||
| # TODO: Create an analysis. | ||
| return Response({"data": "Under construction"}, content_type="application/json") | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,39 +1,43 @@ | ||||
| from rest_framework import status | ||||
| # from rest_framework import status | ||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| from rest_framework.decorators import api_view | ||||
| from rest_framework.response import Response | ||||
|
|
||||
| from utils.firebase import get_collection, get_document, update_document | ||||
| # from utils.firebase import get_collection, get_document, update_document | ||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| from utils.firebase import get_collection | ||||
|
|
||||
|
|
||||
| @api_view(['GET', 'POST']) | ||||
| @api_view(["GET", "POST"]) | ||||
| def lab_results(request, format=None): | ||||
| """Get lab results data.""" | ||||
|
|
||||
| if request.method == 'GET': | ||||
| if request.method == "GET": | ||||
| limit = request.query_params.get("limit", 1000) | ||||
| if limit: | ||||
| limit = int(limit) | ||||
| order_by = request.query_params.get("order_by", "") | ||||
| # TODO: Get any filters from dict(request.query_params) | ||||
| docs = get_collection('tests/leaf/lab_results', order_by=order_by, limit=limit, filters=[]) | ||||
| docs = get_collection( | ||||
| "tests/leaf/lab_results", order_by=order_by, limit=limit, filters=[] | ||||
| ) | ||||
|
Comment on lines
+19
to
+21
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like I recall another |
||||
| return Response(docs, content_type="application/json") | ||||
| if request.method == 'POST': | ||||
| print('TODO: Create lab results') | ||||
|
|
||||
| if request.method == "POST": | ||||
| print("TODO: Create lab results") | ||||
| return NotImplementedError | ||||
|
|
||||
|
|
||||
| @api_view(['GET']) | ||||
| @api_view(["GET"]) | ||||
| def mmes(request, format=None): | ||||
| """Get licensee (MME) data.""" | ||||
|
|
||||
| if request.method == 'GET': | ||||
| if request.method == "GET": | ||||
| limit = request.query_params.get("limit", None) | ||||
| if limit: | ||||
| limit = int(limit) | ||||
| order_by = request.query_params.get("order_by", "") | ||||
| # TODO: Get any filters from dict(request.query_params) | ||||
| # e.g. {"key": "name", "operation": "==", "value": "xyz"} | ||||
| docs = get_collection('tests/leaf/mmes', order_by=order_by, limit=limit, filters=[]) | ||||
| docs = get_collection( | ||||
| "tests/leaf/mmes", order_by=order_by, limit=limit, filters=[] | ||||
| ) | ||||
| return Response(docs, content_type="application/json") | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,32 +1,34 @@ | ||||||||
|
|
||||||||
| from datetime import datetime | ||||||||
| from rest_framework import status | ||||||||
|
|
||||||||
| # from rest_framework import status | ||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| from rest_framework.decorators import api_view | ||||||||
| from rest_framework.response import Response | ||||||||
| from .auth import authenticate | ||||||||
| from utils.firebase import get_document, update_document | ||||||||
|
|
||||||||
| # from .auth import authenticate | ||||||||
| # from utils.firebase import get_document, update_document | ||||||||
|
Comment on lines
+6
to
+8
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
|
|
||||||||
| @api_view(['GET', 'POST']) | ||||||||
| @api_view(["GET", "POST"]) | ||||||||
| def users(request, format=None): | ||||||||
| """Get, update, or create users.""" | ||||||||
| # try: | ||||||||
| # claims = authenticate(request) | ||||||||
| # except: | ||||||||
| # return Response({"error": "Could not authenticate."}, status=status.HTTP_400_BAD_REQUEST) | ||||||||
| # return Response({"error": "Could not authenticate."}, | ||||||||
| # status=status.HTTP_400_BAD_REQUEST) | ||||||||
|
|
||||||||
| # Get user(s). | ||||||||
| if request.method == 'GET': | ||||||||
| if request.method == "GET": | ||||||||
| print("Getting user...") | ||||||||
| # limit = request.query_params.get("limit", None) | ||||||||
| # order_by = request.query_params.get("order_by", "state") | ||||||||
| # # TODO: Get any filters from dict(request.query_params) | ||||||||
| # labs = get_collection('labs', order_by=order_by, limit=limit, filters=[]) | ||||||||
| user = {} | ||||||||
| return Response({ "data": user}, content_type="application/json") | ||||||||
| return Response({"data": user}, content_type="application/json") | ||||||||
|
|
||||||||
| # Update or create user(s). | ||||||||
| elif request.method == 'POST': | ||||||||
| elif request.method == "POST": | ||||||||
| # TODO: Check if user already exists. | ||||||||
| # get_document | ||||||||
| print("Creating a user...") | ||||||||
|
|
@@ -39,4 +41,4 @@ def users(request, format=None): | |||||||
| "photo_url": f"https://robohash.org/${email}?set=set5", | ||||||||
| } | ||||||||
| print(user) | ||||||||
| return Response({ "success": True}, content_type="application/json") | ||||||||
| return Response({"success": True}, content_type="application/json") | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.