Add FRCR toggle functionality to question detail view
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<button
|
||||
class="btn btn-sm {% if question.frcr_appropriate %}btn-success{% else %}btn-outline-secondary{% endif %}"
|
||||
hx-post="{% url 'sbas:toggle_frcr' pk=question.pk %}"
|
||||
hx-swap="outerHTML"
|
||||
title="Toggle FRCR-appropriate"
|
||||
>
|
||||
{% if question.frcr_appropriate %}
|
||||
<i class="bi bi-check-circle me-1" aria-hidden="true"></i>FRCR
|
||||
{% else %}
|
||||
<i class="bi bi-x-circle me-1" aria-hidden="true"></i>FRCR
|
||||
{% endif %}
|
||||
</button>
|
||||
@@ -209,6 +209,11 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-2"><strong>FRCR appropriate:</strong>
|
||||
<div>
|
||||
{% include 'sbas/_frcr_toggle.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -115,6 +115,7 @@ urlpatterns = [
|
||||
views.question_overview,
|
||||
name="question_overview",
|
||||
),
|
||||
path("question/<int:pk>/toggle_frcr/", views.toggle_frcr_appropriate, name="toggle_frcr"),
|
||||
path("category/merge/", views.merge_category, name="merge_category"),
|
||||
#path(
|
||||
# "exam/<int:pk>/scores/<int:cid>/<str:passcode>/",
|
||||
|
||||
+29
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user