From 76d0db0e94202821ce68f1b365e46136d0b068ab Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 29 Oct 2025 21:37:19 +0000 Subject: [PATCH] Add FRCR toggle functionality to question detail view --- sbas/templates/sbas/_frcr_toggle.html | 12 ++++++++++ sbas/templates/sbas/question_detail.html | 5 ++++ sbas/urls.py | 1 + sbas/views.py | 30 +++++++++++++++++++++++- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 sbas/templates/sbas/_frcr_toggle.html diff --git a/sbas/templates/sbas/_frcr_toggle.html b/sbas/templates/sbas/_frcr_toggle.html new file mode 100644 index 00000000..e609e0ed --- /dev/null +++ b/sbas/templates/sbas/_frcr_toggle.html @@ -0,0 +1,12 @@ + diff --git a/sbas/templates/sbas/question_detail.html b/sbas/templates/sbas/question_detail.html index 0b3013bc..4d9bf65a 100644 --- a/sbas/templates/sbas/question_detail.html +++ b/sbas/templates/sbas/question_detail.html @@ -209,6 +209,11 @@ {% endif %} +
FRCR appropriate: +
+ {% include 'sbas/_frcr_toggle.html' %} +
+
diff --git a/sbas/urls.py b/sbas/urls.py index f4f5ec8c..91d35feb 100644 --- a/sbas/urls.py +++ b/sbas/urls.py @@ -115,6 +115,7 @@ urlpatterns = [ views.question_overview, name="question_overview", ), + path("question//toggle_frcr/", views.toggle_frcr_appropriate, name="toggle_frcr"), path("category/merge/", views.merge_category, name="merge_category"), #path( # "exam//scores///", diff --git a/sbas/views.py b/sbas/views.py index 41a62ea5..8b901246 100644 --- a/sbas/views.py +++ b/sbas/views.py @@ -24,7 +24,7 @@ from django.core.cache import cache from django.urls import reverse_lazy, reverse -from django.http import Http404, HttpResponseBadRequest, JsonResponse +from django.http import Http404, HttpResponseBadRequest, JsonResponse, HttpResponseForbidden from django.http import HttpResponseRedirect, HttpResponse @@ -656,6 +656,34 @@ def question_overview(request): return render(request, "sbas/question_overview.html", context) +@login_required +@require_http_methods(["POST", "GET"]) +def toggle_frcr_appropriate(request, pk): + """Toggle or set the Question.frcr_appropriate boolean via HTMX. + + Accepts POST requests. If POST contains 'frcr' parameter its truthiness + will be applied; otherwise the value is toggled. + + Returns the rendered partial `_frcr_toggle.html` so HTMX can swap it in. + """ + question = get_object_or_404(Question, pk=pk) + + # Simple permission: allow staff or users with change permission + if not (request.user.is_staff or request.user.has_perm('sbas.change_question')): + return HttpResponseForbidden("Forbidden") + + # Toggle or set + if request.method == "POST": + val = request.POST.get("frcr") + if val is None: + question.frcr_appropriate = not question.frcr_appropriate + else: + question.frcr_appropriate = str(val).lower() in ("1", "true", "yes", "on") + question.save() + + return render(request, "sbas/_frcr_toggle.html", {"question": question}) + + class UserAnswerTableView(LoginRequiredMixin, SingleTableMixin, FilterView): model = UserAnswer table_class = UserAnswerTable