continue converting answers
This commit is contained in:
+53
-25
@@ -312,7 +312,7 @@ def mark(request, pk, sk):
|
||||
|
||||
answers_dict = {}
|
||||
|
||||
for ans in question.answer.all():
|
||||
for ans in question.answers.all():
|
||||
answers_dict[ans.get_compare_string()] = ans
|
||||
|
||||
marked_answers_set = set(answers_dict.keys())
|
||||
@@ -326,9 +326,9 @@ def mark(request, pk, sk):
|
||||
#]
|
||||
|
||||
# It's probably better to do some processing/checking in the model
|
||||
user_answers = (set([
|
||||
unmarked_user_answers = (set([
|
||||
i.answer.lower()
|
||||
for i in question.cid_user_answers.all() if i.strip() != ""
|
||||
for i in question.cid_user_answers.all() if i.answer.strip() != ""
|
||||
]) - marked_answers_set) # .filter(user=User)
|
||||
|
||||
|
||||
@@ -346,38 +346,58 @@ def mark(request, pk, sk):
|
||||
# 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 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"]:
|
||||
if ans.strip() == "":
|
||||
ans = ans.strip()
|
||||
if ans == "":
|
||||
continue
|
||||
print("correct", ans)
|
||||
print(question.pk)
|
||||
a = Answers()
|
||||
a.question_id = question.pk
|
||||
a.answer = ans.strip()
|
||||
|
||||
a = Answer.objects.filter(answer__iexact=ans).first()
|
||||
|
||||
if a is None:
|
||||
a = Answer()
|
||||
a.question_id = question.pk
|
||||
a.answer = ans
|
||||
|
||||
a.status = Answer.MarkOptions.CORRECT
|
||||
a.save()
|
||||
|
||||
|
||||
# for ans in half_correct.split("--//--"):
|
||||
for ans in marked_answers["half-correct"]:
|
||||
if ans.strip() == "":
|
||||
ans = ans.strip()
|
||||
if ans == "":
|
||||
continue
|
||||
print("halfcorrect", ans)
|
||||
a = HalfMarkAnswers()
|
||||
a.question_id = question.pk
|
||||
a.answer = ans.strip()
|
||||
|
||||
a = Answer.objects.filter(answer__iexact=ans).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"]:
|
||||
if ans.strip() == "":
|
||||
ans = ans.strip()
|
||||
if ans == "":
|
||||
continue
|
||||
print("incorrect", ans)
|
||||
a = IncorrectAnswers()
|
||||
a.question_id = question.pk
|
||||
a.answer = ans.strip()
|
||||
|
||||
a = Answer.objects.filter(answer__iexact=ans).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
|
||||
@@ -390,9 +410,14 @@ def mark(request, pk, sk):
|
||||
return redirect("anatomy:mark", pk=pk, sk=n - 1)
|
||||
|
||||
# Reset user answers (relies on the functional javascript)
|
||||
user_answers = set()
|
||||
unmarked_user_answers = set()
|
||||
else:
|
||||
form = MarkAnatomyQuestionForm()
|
||||
|
||||
correct_answers = question.answers.filter(status = Answer.MarkOptions.CORRECT)
|
||||
half_mark_answers = question.answers.filter(status = Answer.MarkOptions.HALF_MARK)
|
||||
incorrect_answers = question.answers.filter(status = Answer.MarkOptions.INCORRECT)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"anatomy/mark.html",
|
||||
@@ -401,7 +426,10 @@ def mark(request, pk, sk):
|
||||
"form": form,
|
||||
"question": question,
|
||||
"question_details": question_details,
|
||||
"user_answers": user_answers,
|
||||
"user_answers": unmarked_user_answers,
|
||||
"correct_answers": correct_answers,
|
||||
"half_mark_answers": half_mark_answers,
|
||||
"incorrect_answers": incorrect_answers,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user