-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
426 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import structlog | ||
|
||
from django.http import HttpRequest | ||
from django.urls import ResolverMatch | ||
|
||
from .models import Project | ||
|
||
logger = structlog.getLogger(__name__) | ||
|
||
|
||
class ODKProjectMiddleware: | ||
"""Middleware to lookup the current ODK project based on the URL. | ||
The `odk_project` and `odk_projects` attributes are added to the request object. | ||
""" | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request: HttpRequest): | ||
return self.get_response(request) | ||
|
||
def process_view(self, request: HttpRequest, view_func, view_args, view_kwargs): | ||
# Set common context for all views | ||
request.odk_project = None | ||
request.odk_projects = Project.objects.select_related() | ||
# Automatically lookup the current project | ||
resolver_match: ResolverMatch = request.resolver_match | ||
if ( | ||
"odk_publish" in resolver_match.namespaces | ||
and "odk_project_pk" in resolver_match.captured_kwargs | ||
): | ||
odk_project_pk = resolver_match.captured_kwargs["odk_project_pk"] | ||
project = Project.objects.select_related().filter(pk=odk_project_pk).first() | ||
logger.debug("odk_project_pk detected", odk_project_pk=odk_project_pk, project=project) | ||
request.odk_project = project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
app_name = "odk_publish" | ||
urlpatterns = [ | ||
path( | ||
"<int:odk_project_pk>/app-users/", | ||
views.app_users_list, | ||
name="app-users-list", | ||
), | ||
path( | ||
"<int:odk_project_pk>/app-users/generate-qr-codes/", | ||
views.app_users_generate_qr_codes, | ||
name="app-users-generate-qr-codes", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import logging | ||
|
||
from django.http import HttpRequest | ||
from django.contrib.auth.decorators import login_required | ||
from django.shortcuts import render, redirect | ||
|
||
from .etl.load import generate_and_save_app_user_collect_qrcodes | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@login_required | ||
def app_users_list(request: HttpRequest, odk_project_pk): | ||
app_users = request.odk_project.app_users.prefetch_related("app_user_forms__form_template") | ||
return render(request, "odk_publish/app_users.html", {"app_users": app_users}) | ||
|
||
|
||
@login_required | ||
def app_users_generate_qr_codes(request: HttpRequest, odk_project_pk): | ||
generate_and_save_app_user_collect_qrcodes(project=request.odk_project) | ||
return redirect("odk_publish:app-users-list", odk_project_pk=odk_project_pk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.