Allow browsing user scores as admin
This commit is contained in:
@@ -70,7 +70,17 @@
|
||||
<th>Candidate</th>
|
||||
{% for cid in cids %}
|
||||
{% comment %} <th><a href="{% url exam.app_name|add:':exam_scores_cid_user' exam.pk cid %}">{{cid}}</a></th> {% endcomment %}
|
||||
<th><a href="">{{cids_user_id_map|get_item:cid}}</a></th>
|
||||
<th>
|
||||
|
||||
{% if cid|slice:":1" == "u" %}
|
||||
<a href="{% url exam.app_name|add:':exam_scores_user_admin' exam.pk cid|slice:'2:' %}">
|
||||
{% else %}
|
||||
|
||||
<a href="{% url exam.app_name|add:':exam_scores_cid_user_admin' exam.pk cid|slice:'2:' %}">
|
||||
|
||||
{% endif %}
|
||||
|
||||
{{cids_user_id_map|get_item:cid}}</a></th>
|
||||
{% endfor %}
|
||||
|
||||
</tr>
|
||||
|
||||
@@ -229,11 +229,21 @@ def generic_exam_urls(generic_exam_view: GenericExamViews):
|
||||
generic_exam_view.exam_scores_cid_user,
|
||||
name="exam_scores_cid_user",
|
||||
),
|
||||
path(
|
||||
"exam/<int:pk>/scores/<int:cid>/",
|
||||
generic_exam_view.exam_scores_cid_user_admin,
|
||||
name="exam_scores_cid_user_admin",
|
||||
),
|
||||
path(
|
||||
"exam/<int:pk>/scores/",
|
||||
generic_exam_view.exam_scores_user,
|
||||
name="exam_scores_user",
|
||||
),
|
||||
path(
|
||||
"exam/<int:pk>/scores/<int:user_id>/user",
|
||||
generic_exam_view.exam_scores_user_admin,
|
||||
name="exam_scores_user_admin",
|
||||
),
|
||||
path(
|
||||
"exam/<int:pk>/toggle_active",
|
||||
generic_exam_view.exam_toggle_active,
|
||||
|
||||
+14
-1
@@ -1763,7 +1763,17 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
def exam_scores_user(self, request, pk):
|
||||
return self.exam_scores_cid_user(request, pk)
|
||||
|
||||
def exam_scores_cid_user(self, request, pk, cid=None, passcode=""):
|
||||
@method_decorator(user_passes_test(lambda u: u.is_superuser))
|
||||
def exam_scores_user_admin(self, request, pk, user_id):
|
||||
user = User.objects.get(id=user_id)
|
||||
return self.exam_scores_cid_user(request, pk, user=user)
|
||||
|
||||
@method_decorator(user_passes_test(lambda u: u.is_superuser))
|
||||
def exam_scores_cid_user_admin(self, request, pk, cid):
|
||||
user = CidUser.objects.get(cid=cid)
|
||||
return self.exam_scores_cid_user(request, pk, cid, user.passcode)
|
||||
|
||||
def exam_scores_cid_user(self, request, pk, cid=None, passcode="", user=None):
|
||||
exam = get_object_or_404(self.Exam, pk=pk)
|
||||
|
||||
if not exam.exam_mode:
|
||||
@@ -1772,6 +1782,9 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
if cid is not None and not exam.check_cid_user(cid, passcode, request):
|
||||
raise Http404("Error accessing exam")
|
||||
|
||||
if user is not None:
|
||||
request.user = user
|
||||
|
||||
questions = (
|
||||
exam.exam_questions.all()
|
||||
) # .prefetch_related("cid_user_answers", "answers")
|
||||
|
||||
Reference in New Issue
Block a user