Merge branch 'master' of ssh://git.xkjq.uk:30001/ross/rad

This commit is contained in:
Ross
2021-08-08 10:11:23 +01:00
9 changed files with 72 additions and 49 deletions
+3 -1
View File
@@ -32,9 +32,11 @@
<br />
{% for series in question.series.all %}
<div class="series-block">
Series {{forloop.counter0 }}:<br />
Series {{forloop.counter }}:<br />
{{series.get_block}}
</div>
{% empty %}
No series
{% endfor %}
<div>
Author(s): {{question.get_authors}}
+3 -1
View File
@@ -49,7 +49,9 @@
<button type="submit" name="next" class="save btn btn-default" title="Save answer and move to next question">Next answer</button>
<!-- <button type="submit" name="skip" class="save btn btn-default">Skip</button> -->
{% else %}
(no more answers for this question to mark)
{% if not unmarked %}
All question answers marker. <a href="{% url 'longs:mark_overview' pk=exam.pk %}">Return to marking overview</a>
{% endif %}
{% endif %}
</form>
</div>
+14 -12
View File
@@ -571,21 +571,21 @@ def loadJsonAnswer(answer):
if (not isinstance(answer["cid"], int)) or (
not isinstance(eid, int) or (not isinstance(answer["ans"], str))
):
return JsonResponse(
return False, JsonResponse(
{"success": False, "error": "cid or eid or answers not defined"}
)
# The model should catch invalid data but this should be less intensive
max_int = 999999999999999999999
if answer["cid"] > max_int or eid > max_int:
return JsonResponse({"success": False, "error": "invalid cid"})
return False, JsonResponse({"success": False, "error": "invalid cid"})
exam = get_object_or_404(Exam, pk=eid)
if not exam.active:
return JsonResponse(
{"success": False, "error": "No active exam: {}".format(eid)}
)
#if not exam.active:
# return False, JsonResponse(
# {"success": False, "error": "No active exam: {}".format(eid)}
# )
exiting_answers = CidUserAnswer.objects.filter(
question__id=answer["qid"], exam__id=eid, cid=answer["cid"]
@@ -627,7 +627,7 @@ def loadJsonAnswer(answer):
ans.full_clean()
ans.save()
return True
return True, None
@login_required
@@ -650,7 +650,7 @@ def mark_answer(request, pk, sk, tk):
raise Http404("Exam question does not exist")
try:
answer = question.cid_user_answers.get(cid=tk)
answer = question.cid_user_answers.get(cid=tk, exam__id=pk)
except ObjectDoesNotExist:
raise Http404("User answer does not exist")
@@ -678,6 +678,8 @@ def mark_answer(request, pk, sk, tk):
if "next" in request.POST:
return redirect("longs:mark_answer", pk=pk, sk=sk, tk=next_unmarked_id)
if "save" in request.POST:
return redirect("longs:mark_answer", pk=pk, sk=sk, tk=tk)
#elif "previous" in request.POST:
# return redirect("longs:mark", pk=pk, sk=n - 1)
@@ -720,7 +722,7 @@ def mark(request, pk, sk):
raise Http404("Exam question does not exist")
user_answers = question.cid_user_answers.all()
user_answers = question.cid_user_answers.filter(exam__id=pk)
return render(
request,
@@ -742,7 +744,7 @@ def exam_scores_cid(request, pk):
questions = exam.exam_questions.all()
cids = (
CidUserAnswer.objects.filter(question__in=questions)
CidUserAnswer.objects.filter(question__in=questions, exam__id=pk)
.order_by("cid")
.values_list("cid", flat=True)
.distinct()
@@ -762,7 +764,7 @@ def exam_scores_cid(request, pk):
user_names[cid] = cid
for q in questions:
# Get user answer
s = q.cid_user_answers.filter(cid=cid).first()
s = q.cid_user_answers.filter(cid=cid, exam__id=pk).first()
if not s:
# skip if no answer, (score 4)
@@ -855,7 +857,7 @@ def exam_scores_cid_user(request, pk, sk):
for q in questions:
# Get user answer
user_answer = q.cid_user_answers.filter(cid=cid).first()
user_answer = q.cid_user_answers.filter(cid=cid, exam__id=pk).first()