continue converting answers
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# Generated by Django 3.1.3 on 2020-11-19 19:41
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('anatomy', '0002_exam_active'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Answer',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('answer', models.CharField(max_length=500)),
|
||||
('status', models.CharField(choices=[('', 'Unmarked'), ('0', 'Incorrect'), ('1', 'Half mark'), ('2', 'Correct')], default='', max_length=1)),
|
||||
('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='answers', to='anatomy.anatomyquestion')),
|
||||
],
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='halfmarkanswers',
|
||||
name='question',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='incorrectanswers',
|
||||
name='question',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Answers',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='HalfMarkAnswers',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='IncorrectAnswers',
|
||||
),
|
||||
]
|
||||
@@ -7,6 +7,8 @@ from django.utils.html import format_html
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
image_storage = FileSystemStorage(
|
||||
# Physical file location ROOT
|
||||
location=u"{0}/anatomy/".format(settings.MEDIA_ROOT),
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
<div class="marking-list">Marked:
|
||||
<ul id="marked-answer-list" class="answer-list">
|
||||
{% for answer in question.answers.all %}
|
||||
{% for answer in correct_answers %}
|
||||
<li class="correct">{{ answer }} </li>
|
||||
{% endfor %}
|
||||
{% for answer in question.half_mark_answers.all %}
|
||||
{% for answer in half_mark_answers %}
|
||||
<li class="half-correct">{{ answer }} </li>
|
||||
{% endfor %}
|
||||
{% for answer in question.incorrect_answers.all %}
|
||||
{% for answer in incorrect_answers %}
|
||||
<li class="incorrect">{{ answer }} </li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
+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