diff --git a/anatomy/views.py b/anatomy/views.py index 10043f48..8e75e75e 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -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: diff --git a/rapids/migrations/0033_answermarks.py b/rapids/migrations/0033_answermarks.py new file mode 100644 index 00000000..d11b11df --- /dev/null +++ b/rapids/migrations/0033_answermarks.py @@ -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')), + ], + ), + ] diff --git a/rapids/models.py b/rapids/models.py index 10797fdf..411621d7 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -661,4 +661,22 @@ class CidUserAnswer(models.Model): mark = 0 else: mark = "unmarked" - return mark \ No newline at end of file + 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 + ) \ No newline at end of file diff --git a/rapids/templates/rapids/mark.html b/rapids/templates/rapids/mark.html index 63accf9d..617c7728 100644 --- a/rapids/templates/rapids/mark.html +++ b/rapids/templates/rapids/mark.html @@ -34,7 +34,7 @@ Region: {{ question.get_regions }}, Abnormalities: {{ question.get_abnormalities