.
This commit is contained in:
+26
-67
@@ -573,15 +573,15 @@ def loadJsonAnswer(answer):
|
||||
|
||||
|
||||
def mark_all(request, exam_pk, sk):
|
||||
return mark(request, exam_pk, sk, exam_answers_only=False)
|
||||
return mark(request, exam_pk, sk, unmarked_exam_answers_only=False)
|
||||
|
||||
# @user_passes_test(user_is_admin, login_url="/accounts/login")
|
||||
@login_required
|
||||
def mark(request, exam_pk, sk, exam_answers_only=True):
|
||||
def mark(request, exam_pk, sk, unmarked_exam_answers_only=True):
|
||||
exam = get_object_or_404(Exam, pk=exam_pk)
|
||||
|
||||
mark_url = "rapids:mark"
|
||||
if not exam_answers_only:
|
||||
if not unmarked_exam_answers_only:
|
||||
mark_url = "rapids:mark_all"
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
@@ -613,7 +613,7 @@ def mark(request, exam_pk, sk, exam_answers_only=True):
|
||||
# i.answer.lower() for i in question.incorrect_answers.all()
|
||||
# ]
|
||||
|
||||
if exam_answers_only:
|
||||
if unmarked_exam_answers_only:
|
||||
unmarked_user_answers = question.get_unmarked_user_answers(exam_pk=exam_pk)
|
||||
else:
|
||||
unmarked_user_answers = question.get_unmarked_user_answers()
|
||||
@@ -630,76 +630,35 @@ def mark(request, exam_pk, sk, exam_answers_only=True):
|
||||
return redirect(mark_url, exam_pk=exam_pk, sk=n + 1)
|
||||
|
||||
cd = form.cleaned_data
|
||||
# correct = cd.get("correct")
|
||||
# half_correct = cd.get("half_correct")
|
||||
# incorrect = cd.get("incorrect")
|
||||
print (cd)
|
||||
print(dir(cd))
|
||||
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()
|
||||
marked_answers = json.loads(cd.get("marked_answers"))
|
||||
|
||||
# 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.status = status
|
||||
a.save()
|
||||
|
||||
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()
|
||||
if "next" in request.POST:
|
||||
return redirect(mark_url, exam_pk=exam_pk, sk=n + 1)
|
||||
elif "previous" in request.POST:
|
||||
@@ -710,7 +669,7 @@ def mark(request, exam_pk, sk, exam_answers_only=True):
|
||||
else:
|
||||
form = MarkRapidQuestionForm()
|
||||
|
||||
if exam_answers_only:
|
||||
if unmarked_exam_answers_only:
|
||||
correct_answers = []
|
||||
half_mark_answers = []
|
||||
incorrect_answers = []
|
||||
@@ -740,7 +699,7 @@ def mark(request, exam_pk, sk, exam_answers_only=True):
|
||||
"correct_answers": correct_answers,
|
||||
"half_mark_answers": half_mark_answers,
|
||||
"incorrect_answers": incorrect_answers,
|
||||
"exam_answers_only": exam_answers_only,
|
||||
"unmarked_exam_answers_only": unmarked_exam_answers_only,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user