.
This commit is contained in:
+10
-49
@@ -337,19 +337,19 @@ def mark(request, pk, sk):
|
|||||||
return redirect("anatomy:mark", pk=pk, sk=n + 1)
|
return redirect("anatomy:mark", pk=pk, sk=n + 1)
|
||||||
|
|
||||||
cd = form.cleaned_data
|
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
|
marked_answers = json.loads(cd.get("marked_answers"))
|
||||||
# question.answers.all().delete()
|
|
||||||
# question.half_mark_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"]:
|
to_run = (
|
||||||
|
("correct", Answer.MarkOptions.CORRECT),
|
||||||
|
("half-correct", Answer.MarkOptions.HALF_MARK),
|
||||||
|
("incorrect", Answer.MarkOptions.INCORRECT),
|
||||||
|
)
|
||||||
|
|
||||||
|
for status_string, status in to_run:
|
||||||
|
for ans in marked_answers[status_string]:
|
||||||
ans = ans.strip()
|
ans = ans.strip()
|
||||||
if ans == "":
|
if ans == "":
|
||||||
continue
|
continue
|
||||||
@@ -363,48 +363,9 @@ def mark(request, pk, sk):
|
|||||||
a.question_id = question.pk
|
a.question_id = question.pk
|
||||||
a.answer = ans
|
a.answer = ans
|
||||||
|
|
||||||
a.status = Answer.MarkOptions.CORRECT
|
a.status = status
|
||||||
a.save()
|
a.save()
|
||||||
|
|
||||||
# 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()
|
|
||||||
if "next" in request.POST:
|
if "next" in request.POST:
|
||||||
return redirect("anatomy:mark", pk=pk, sk=n + 1)
|
return redirect("anatomy:mark", pk=pk, sk=n + 1)
|
||||||
elif "previous" in request.POST:
|
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')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -662,3 +662,21 @@ class CidUserAnswer(models.Model):
|
|||||||
else:
|
else:
|
||||||
mark = "unmarked"
|
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 %}
|
<form method="POST" class="post-form">{% csrf_token %}
|
||||||
{% if not question.normal %}
|
{% if not question.normal %}
|
||||||
Click each answer to toggle through marks awarded (as per colour)<br/>
|
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>
|
Showing exam answers only <a href="{% url 'rapids:mark_all' exam.id question_number %}">(view all)</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
Showing all answers <a href="{% url 'rapids:mark' exam.id question_number %}">(view unmarked exam answers)</a>
|
Showing all answers <a href="{% url 'rapids:mark' exam.id question_number %}">(view unmarked exam answers)</a>
|
||||||
|
|||||||
+16
-57
@@ -573,15 +573,15 @@ def loadJsonAnswer(answer):
|
|||||||
|
|
||||||
|
|
||||||
def mark_all(request, exam_pk, sk):
|
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")
|
# @user_passes_test(user_is_admin, login_url="/accounts/login")
|
||||||
@login_required
|
@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)
|
exam = get_object_or_404(Exam, pk=exam_pk)
|
||||||
|
|
||||||
mark_url = "rapids:mark"
|
mark_url = "rapids:mark"
|
||||||
if not exam_answers_only:
|
if not unmarked_exam_answers_only:
|
||||||
mark_url = "rapids:mark_all"
|
mark_url = "rapids:mark_all"
|
||||||
|
|
||||||
questions = exam.exam_questions.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()
|
# 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)
|
unmarked_user_answers = question.get_unmarked_user_answers(exam_pk=exam_pk)
|
||||||
else:
|
else:
|
||||||
unmarked_user_answers = question.get_unmarked_user_answers()
|
unmarked_user_answers = question.get_unmarked_user_answers()
|
||||||
@@ -630,21 +630,19 @@ def mark(request, exam_pk, sk, exam_answers_only=True):
|
|||||||
return redirect(mark_url, exam_pk=exam_pk, sk=n + 1)
|
return redirect(mark_url, exam_pk=exam_pk, sk=n + 1)
|
||||||
|
|
||||||
cd = form.cleaned_data
|
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
|
marked_answers = json.loads(cd.get("marked_answers"))
|
||||||
# question.answers.all().delete()
|
|
||||||
# question.half_mark_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"]:
|
to_run = (
|
||||||
|
("correct", Answer.MarkOptions.CORRECT),
|
||||||
|
("half-correct", Answer.MarkOptions.HALF_MARK),
|
||||||
|
("incorrect", Answer.MarkOptions.INCORRECT),
|
||||||
|
)
|
||||||
|
|
||||||
|
for status_string, status in to_run:
|
||||||
|
for ans in marked_answers[status_string]:
|
||||||
ans = ans.strip()
|
ans = ans.strip()
|
||||||
if ans == "":
|
if ans == "":
|
||||||
continue
|
continue
|
||||||
@@ -658,48 +656,9 @@ def mark(request, exam_pk, sk, exam_answers_only=True):
|
|||||||
a.question_id = question.pk
|
a.question_id = question.pk
|
||||||
a.answer = ans
|
a.answer = ans
|
||||||
|
|
||||||
a.status = Answer.MarkOptions.CORRECT
|
a.status = status
|
||||||
a.save()
|
a.save()
|
||||||
|
|
||||||
# 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()
|
|
||||||
if "next" in request.POST:
|
if "next" in request.POST:
|
||||||
return redirect(mark_url, exam_pk=exam_pk, sk=n + 1)
|
return redirect(mark_url, exam_pk=exam_pk, sk=n + 1)
|
||||||
elif "previous" in request.POST:
|
elif "previous" in request.POST:
|
||||||
@@ -710,7 +669,7 @@ def mark(request, exam_pk, sk, exam_answers_only=True):
|
|||||||
else:
|
else:
|
||||||
form = MarkRapidQuestionForm()
|
form = MarkRapidQuestionForm()
|
||||||
|
|
||||||
if exam_answers_only:
|
if unmarked_exam_answers_only:
|
||||||
correct_answers = []
|
correct_answers = []
|
||||||
half_mark_answers = []
|
half_mark_answers = []
|
||||||
incorrect_answers = []
|
incorrect_answers = []
|
||||||
@@ -740,7 +699,7 @@ def mark(request, exam_pk, sk, exam_answers_only=True):
|
|||||||
"correct_answers": correct_answers,
|
"correct_answers": correct_answers,
|
||||||
"half_mark_answers": half_mark_answers,
|
"half_mark_answers": half_mark_answers,
|
||||||
"incorrect_answers": incorrect_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