This commit is contained in:
Ross
2021-12-19 18:10:43 +00:00
parent 20af929970
commit fc7dbfb603
4 changed files with 12 additions and 9 deletions
+6 -2
View File
@@ -147,8 +147,12 @@ class ExamBase(models.Model):
authors = [i for i in self.author.all()]
return authors
def check_cid_user(self, cid, passcode):
def check_cid_user(self, cid, passcode, request=None):
if request is not None and request.user.is_superuser():
return True
if self.valid_users.exists():
user = self.valid_users.filter(cid=cid).first()
if not user or user.passcode != passcode:
@@ -270,7 +274,7 @@ class CidUser(models.Model):
"test@xkjq.uk",
[self.email, self.supervisor_email],
fail_silently=False,
html_message=html_msg
html_message=html_msg,
)
except SMTPException as e:
return False, e
+3 -3
View File
@@ -936,7 +936,7 @@ class ExamViews(View, LoginRequiredMixin):
user_answers_marks = defaultdict(list)
user_answers = defaultdict(list)
user_names = {}
cid_passcodes = {}
#cid_passcodes = {}
by_question = defaultdict(dict)
unmarked = set()
@@ -954,7 +954,7 @@ class ExamViews(View, LoginRequiredMixin):
for cid_user_answer in cid_user_answers:
# Convoluted (probably...)
cid = cid_user_answer.cid
cid_passcodes[cid] = cid_user_answer.passcode
#cid_passcodes[cid] = cid_user_answer.passcode
cids.add(cid)
s = cid_user_answer
user_names[cid] = cid
@@ -1055,7 +1055,7 @@ class ExamViews(View, LoginRequiredMixin):
f"{self.app_name}/exam_scores_new.html",
{
"cids": sorted(cids),
"cid_passcodes": cid_passcodes,
#"cid_passcodes": cid_passcodes,
"exam": exam,
"unmarked": unmarked,
"questions": questions,
+1 -1
View File
@@ -37,7 +37,7 @@
<tr>
<th>Candidate</th>
{% for cid in cids %}
<th><a href="{% url 'sbas:exam_scores_cid_user' exam.pk cid cid_passcodes|get_item:cid %}">{{cid}}</a></th>
<th><a href="{% url 'sbas:exam_scores_cid_user' exam.pk cid 'None' %}">{{cid}}</a></th>
{% comment %} <th><a href="">{{cid}}</a></th> {% endcomment %}
{% endfor %}
+2 -3
View File
@@ -81,11 +81,10 @@ def active_exams(request):
return render(request, "sbas/available_exam_list.html", {"exams": active_exams})
def exam_scores_cid_user(request, pk, sk, passcode):
def exam_scores_cid_user(request, pk, cid, passcode):
exam = get_object_or_404(Exam, pk=pk)
cid = sk
if not exam.check_cid_user(cid, passcode):
if not exam.check_cid_user(cid, passcode, request):
raise Http404("Error accessing exam")
questions = exam.exam_questions.all()