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.urls import reverse
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
image_storage = FileSystemStorage(
|
image_storage = FileSystemStorage(
|
||||||
# Physical file location ROOT
|
# Physical file location ROOT
|
||||||
location=u"{0}/anatomy/".format(settings.MEDIA_ROOT),
|
location=u"{0}/anatomy/".format(settings.MEDIA_ROOT),
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
<form method="POST" class="post-form">{% csrf_token %}
|
<form method="POST" class="post-form">{% csrf_token %}
|
||||||
<div class="marking-list">Marked:
|
<div class="marking-list">Marked:
|
||||||
<ul id="marked-answer-list" class="answer-list">
|
<ul id="marked-answer-list" class="answer-list">
|
||||||
{% for answer in question.answers.all %}
|
{% for answer in correct_answers %}
|
||||||
<li class="correct">{{ answer }} </li>
|
<li class="correct">{{ answer }} </li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for answer in question.half_mark_answers.all %}
|
{% for answer in half_mark_answers %}
|
||||||
<li class="half-correct">{{ answer }} </li>
|
<li class="half-correct">{{ answer }} </li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for answer in question.incorrect_answers.all %}
|
{% for answer in incorrect_answers %}
|
||||||
<li class="incorrect">{{ answer }} </li>
|
<li class="incorrect">{{ answer }} </li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
+50
-22
@@ -312,7 +312,7 @@ def mark(request, pk, sk):
|
|||||||
|
|
||||||
answers_dict = {}
|
answers_dict = {}
|
||||||
|
|
||||||
for ans in question.answer.all():
|
for ans in question.answers.all():
|
||||||
answers_dict[ans.get_compare_string()] = ans
|
answers_dict[ans.get_compare_string()] = ans
|
||||||
|
|
||||||
marked_answers_set = set(answers_dict.keys())
|
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
|
# It's probably better to do some processing/checking in the model
|
||||||
user_answers = (set([
|
unmarked_user_answers = (set([
|
||||||
i.answer.lower()
|
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)
|
]) - marked_answers_set) # .filter(user=User)
|
||||||
|
|
||||||
|
|
||||||
@@ -346,38 +346,58 @@ def mark(request, pk, sk):
|
|||||||
# incorrect = cd.get("incorrect")
|
# incorrect = cd.get("incorrect")
|
||||||
marked_answers = json.loads(cd.get("marked_answers"))
|
marked_answers = json.loads(cd.get("marked_answers"))
|
||||||
|
|
||||||
# This is mildly dangerous as we delete all answers
|
## This is mildly dangerous as we delete all answers
|
||||||
question.answers.all().delete()
|
#question.answers.all().delete()
|
||||||
question.half_mark_answers.all().delete()
|
#question.half_mark_answers.all().delete()
|
||||||
question.incorrect_answers.all().delete()
|
#question.incorrect_answers.all().delete()
|
||||||
|
|
||||||
# This should probably use json (or something else...)
|
# This should probably use json (or something else...)
|
||||||
# ajax.....
|
# ajax.....
|
||||||
for ans in marked_answers["correct"]:
|
for ans in marked_answers["correct"]:
|
||||||
if ans.strip() == "":
|
ans = ans.strip()
|
||||||
|
if ans == "":
|
||||||
continue
|
continue
|
||||||
print("correct", ans)
|
|
||||||
print(question.pk)
|
a = Answer.objects.filter(answer__iexact=ans).first()
|
||||||
a = Answers()
|
|
||||||
|
if a is None:
|
||||||
|
a = Answer()
|
||||||
a.question_id = question.pk
|
a.question_id = question.pk
|
||||||
a.answer = ans.strip()
|
a.answer = ans
|
||||||
|
|
||||||
|
a.status = Answer.MarkOptions.CORRECT
|
||||||
a.save()
|
a.save()
|
||||||
|
|
||||||
|
|
||||||
# for ans in half_correct.split("--//--"):
|
# for ans in half_correct.split("--//--"):
|
||||||
for ans in marked_answers["half-correct"]:
|
for ans in marked_answers["half-correct"]:
|
||||||
if ans.strip() == "":
|
ans = ans.strip()
|
||||||
|
if ans == "":
|
||||||
continue
|
continue
|
||||||
print("halfcorrect", ans)
|
|
||||||
a = HalfMarkAnswers()
|
a = Answer.objects.filter(answer__iexact=ans).first()
|
||||||
|
|
||||||
|
if a is None:
|
||||||
|
a = Answer()
|
||||||
a.question_id = question.pk
|
a.question_id = question.pk
|
||||||
a.answer = ans.strip()
|
a.answer = ans
|
||||||
|
|
||||||
|
a.status = Answer.MarkOptions.HALF_MARK
|
||||||
a.save()
|
a.save()
|
||||||
|
|
||||||
for ans in marked_answers["incorrect"]:
|
for ans in marked_answers["incorrect"]:
|
||||||
if ans.strip() == "":
|
ans = ans.strip()
|
||||||
|
if ans == "":
|
||||||
continue
|
continue
|
||||||
print("incorrect", ans)
|
|
||||||
a = IncorrectAnswers()
|
a = Answer.objects.filter(answer__iexact=ans).first()
|
||||||
|
|
||||||
|
if a is None:
|
||||||
|
a = Answer()
|
||||||
a.question_id = question.pk
|
a.question_id = question.pk
|
||||||
a.answer = ans.strip()
|
a.answer = ans
|
||||||
|
|
||||||
|
a.status = Answer.MarkOptions.INCORRECT
|
||||||
a.save()
|
a.save()
|
||||||
# answer = form.save(commit=False)
|
# answer = form.save(commit=False)
|
||||||
# answer.user = request.user
|
# answer.user = request.user
|
||||||
@@ -390,9 +410,14 @@ def mark(request, pk, sk):
|
|||||||
return redirect("anatomy:mark", pk=pk, sk=n - 1)
|
return redirect("anatomy:mark", pk=pk, sk=n - 1)
|
||||||
|
|
||||||
# Reset user answers (relies on the functional javascript)
|
# Reset user answers (relies on the functional javascript)
|
||||||
user_answers = set()
|
unmarked_user_answers = set()
|
||||||
else:
|
else:
|
||||||
form = MarkAnatomyQuestionForm()
|
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(
|
return render(
|
||||||
request,
|
request,
|
||||||
"anatomy/mark.html",
|
"anatomy/mark.html",
|
||||||
@@ -401,7 +426,10 @@ def mark(request, pk, sk):
|
|||||||
"form": form,
|
"form": form,
|
||||||
"question": question,
|
"question": question,
|
||||||
"question_details": question_details,
|
"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