.
This commit is contained in:
+21
-60
@@ -337,74 +337,35 @@ def mark(request, pk, sk):
|
||||
return redirect("anatomy:mark", pk=pk, sk=n + 1)
|
||||
|
||||
cd = form.cleaned_data
|
||||
# correct = cd.get("correct")
|
||||
# half_correct = cd.get("half_correct")
|
||||
# incorrect = cd.get("incorrect")
|
||||
|
||||
marked_answers = json.loads(cd.get("marked_answers"))
|
||||
|
||||
## This is mildly dangerous as we delete all answers
|
||||
# question.answers.all().delete()
|
||||
# question.half_mark_answers.all().delete()
|
||||
# question.incorrect_answers.all().delete()
|
||||
|
||||
# This should probably use json (or something else...)
|
||||
# ajax.....
|
||||
for ans in marked_answers["correct"]:
|
||||
ans = ans.strip()
|
||||
if ans == "":
|
||||
continue
|
||||
to_run = (
|
||||
("correct", Answer.MarkOptions.CORRECT),
|
||||
("half-correct", Answer.MarkOptions.HALF_MARK),
|
||||
("incorrect", Answer.MarkOptions.INCORRECT),
|
||||
)
|
||||
|
||||
a = Answer.objects.filter(
|
||||
answer__iexact=ans, question_id=question.pk
|
||||
).first()
|
||||
for status_string, status in to_run:
|
||||
for ans in marked_answers[status_string]:
|
||||
ans = ans.strip()
|
||||
if ans == "":
|
||||
continue
|
||||
|
||||
if a is None:
|
||||
a = Answer()
|
||||
a.question_id = question.pk
|
||||
a.answer = ans
|
||||
a = Answer.objects.filter(
|
||||
answer__iexact=ans, question_id=question.pk
|
||||
).first()
|
||||
|
||||
a.status = Answer.MarkOptions.CORRECT
|
||||
a.save()
|
||||
if a is None:
|
||||
a = Answer()
|
||||
a.question_id = question.pk
|
||||
a.answer = ans
|
||||
|
||||
# for ans in half_correct.split("--//--"):
|
||||
for ans in marked_answers["half-correct"]:
|
||||
ans = ans.strip()
|
||||
if ans == "":
|
||||
continue
|
||||
|
||||
a = Answer.objects.filter(
|
||||
answer__iexact=ans, question_id=question.pk
|
||||
).first()
|
||||
|
||||
if a is None:
|
||||
a = Answer()
|
||||
a.question_id = question.pk
|
||||
a.answer = ans
|
||||
|
||||
a.status = Answer.MarkOptions.HALF_MARK
|
||||
a.save()
|
||||
|
||||
for ans in marked_answers["incorrect"]:
|
||||
ans = ans.strip()
|
||||
if ans == "":
|
||||
continue
|
||||
|
||||
a = Answer.objects.filter(
|
||||
answer__iexact=ans, question_id=question.pk
|
||||
).first()
|
||||
|
||||
if a is None:
|
||||
a = Answer()
|
||||
a.question_id = question.pk
|
||||
a.answer = ans
|
||||
|
||||
a.status = Answer.MarkOptions.INCORRECT
|
||||
a.save()
|
||||
# answer = form.save(commit=False)
|
||||
# answer.user = request.user
|
||||
# answer.question = question
|
||||
# answer.published_date = timezone.now()
|
||||
# answer.save()
|
||||
a.status = status
|
||||
a.save()
|
||||
|
||||
if "next" in request.POST:
|
||||
return redirect("anatomy:mark", pk=pk, sk=n + 1)
|
||||
elif "previous" in request.POST:
|
||||
|
||||
Reference in New Issue
Block a user