.
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:
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 3.2.8 on 2021-10-16 09:24
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('rapids', '0032_exam_double_mark'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AnswerMarks',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('score', models.CharField(choices=[('', 'Unmarked'), ('0', 'Incorrect'), ('1', 'Half mark'), ('2', 'Correct')], max_length=1)),
|
||||
('marker', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rapid_marks', to=settings.AUTH_USER_MODEL)),
|
||||
('user_answer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='mark', to='rapids.ciduseranswer')),
|
||||
],
|
||||
),
|
||||
]
|
||||
+19
-1
@@ -661,4 +661,22 @@ class CidUserAnswer(models.Model):
|
||||
mark = 0
|
||||
else:
|
||||
mark = "unmarked"
|
||||
return mark
|
||||
return mark
|
||||
|
||||
@reversion.register
|
||||
class AnswerMarks(models.Model):
|
||||
score = models.CharField(
|
||||
max_length=1, choices=Answer.MarkOptions.choices
|
||||
)
|
||||
|
||||
#mark_reason = models.TextField(null=True, blank=True, help_text="Reason for the given mark - not visible to candidates")
|
||||
|
||||
#candidate_feedback = models.TextField(null=True, blank=True, help_text="Feedback for the candidate")
|
||||
|
||||
marker = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL, related_name="rapid_marks", on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
user_answer = models.ForeignKey(
|
||||
CidUserAnswer, related_name="mark", on_delete=models.SET_NULL, null=True, blank=True
|
||||
)
|
||||
@@ -34,7 +34,7 @@ Region: {{ question.get_regions }}, Abnormalities: {{ question.get_abnormalities
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{% if not question.normal %}
|
||||
Click each answer to toggle through marks awarded (as per colour)<br/>
|
||||
{% if exam_answers_only %}
|
||||
{% if unmarked_exam_answers_only %}
|
||||
Showing exam answers only <a href="{% url 'rapids:mark_all' exam.id question_number %}">(view all)</a>
|
||||
{% else %}
|
||||
Showing all answers <a href="{% url 'rapids:mark' exam.id question_number %}">(view unmarked exam answers)</a>
|
||||
|
||||
+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