refactor: improve score distribution display and enhance HTMX handling in exam views
This commit is contained in:
@@ -63,9 +63,8 @@
|
|||||||
|
|
||||||
{% if plot %}
|
{% if plot %}
|
||||||
<div class="card bg-dark text-light border-secondary mb-4 shadow-sm">
|
<div class="card bg-dark text-light border-secondary mb-4 shadow-sm">
|
||||||
<div class="card-header border-secondary d-flex justify-content-between align-items-center">
|
<div class="card-header border-secondary">
|
||||||
<h6 class="mb-0">Distribution of Scores</h6>
|
<h6 class="mb-0">Distribution of Scores</h6>
|
||||||
<span class="badge bg-secondary">low scores (<20% max) excluded from statistics</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body p-0">
|
<div class="card-body p-0">
|
||||||
<div id="stats-plot-wrapper">
|
<div id="stats-plot-wrapper">
|
||||||
|
|||||||
+6
-8
@@ -4066,10 +4066,6 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
pass_rate = 0.0
|
pass_rate = 0.0
|
||||||
|
|
||||||
if len(user_scores_list) >= 1:
|
if len(user_scores_list) >= 1:
|
||||||
lower_score_bound = max_score / 5
|
|
||||||
bounded_scores = [i for i in user_scores_list if i > lower_score_bound]
|
|
||||||
if bounded_scores:
|
|
||||||
user_scores_list = bounded_scores
|
|
||||||
|
|
||||||
mean = round(statistics.mean(user_scores_list), 2)
|
mean = round(statistics.mean(user_scores_list), 2)
|
||||||
median = round(statistics.median(user_scores_list), 2)
|
median = round(statistics.median(user_scores_list), 2)
|
||||||
@@ -4248,12 +4244,14 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
exam.save()
|
exam.save()
|
||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.http import HttpResponseRedirect
|
|
||||||
url = reverse(f"{self.app_name}:exam_scores_all", kwargs={"pk": pk})
|
url = reverse(f"{self.app_name}:exam_scores_all", kwargs={"pk": pk})
|
||||||
response = HttpResponseRedirect(url)
|
|
||||||
if request.htmx:
|
if request.htmx:
|
||||||
response["HX-Redirect"] = url
|
# Return 200 OK with HX-Redirect header to trigger client-side redirect in HTMX
|
||||||
return response
|
return HttpResponse("", headers={"HX-Redirect": url})
|
||||||
|
|
||||||
|
# Standard non-HTMX redirect
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
def toggle_candidate_stats_exclusion(self, request, pk):
|
def toggle_candidate_stats_exclusion(self, request, pk):
|
||||||
exam = get_object_or_404(self.Exam, pk=pk)
|
exam = get_object_or_404(self.Exam, pk=pk)
|
||||||
|
|||||||
@@ -417,6 +417,21 @@ CHANNEL_LAYERS = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def show_toolbar(request):
|
||||||
|
if request.headers.get("HX-Request") or getattr(request, "htmx", False):
|
||||||
|
return False
|
||||||
|
if request.headers.get("x-requested-with") == "XMLHttpRequest":
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
from debug_toolbar.middleware import show_toolbar as default_show_toolbar
|
||||||
|
return default_show_toolbar(request)
|
||||||
|
except ImportError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
DEBUG_TOOLBAR_CONFIG = {
|
||||||
|
"SHOW_TOOLBAR_CALLBACK": "rad.settings.show_toolbar",
|
||||||
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .settings_local import *
|
from .settings_local import *
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user