This commit is contained in:
Ross
2021-09-21 18:34:07 +01:00
parent 0e3ca7df71
commit d30feb34ac
3 changed files with 30 additions and 26 deletions
+27 -21
View File
@@ -129,8 +129,8 @@ class AnatomyQuestion(models.Model):
def __str__(self): def __str__(self):
# Get first answer # Get first answer
return "{} [{}, {}]".format( return "{}: {} [{}, {}]".format(
self.get_primary_answer(), self.modality, self.structure self.question_type, self.get_primary_answer(), self.modality, self.structure
) )
# Get associated exams # Get associated exams
e = self.exams.all().values_list("name", flat=True) e = self.exams.all().values_list("name", flat=True)
@@ -170,12 +170,13 @@ class AnatomyQuestion(models.Model):
def get_unmarked_answers(self, exam_pk=None): def get_unmarked_answers(self, exam_pk=None):
if exam_pk is None: if exam_pk is None:
user_answers = set( user_answers = set([i.answer_compare for i in self.cid_user_answers.all()])
[i.answer_compare for i in self.cid_user_answers.all()]
)
else: else:
user_answers = set( user_answers = set(
[i.answer_compare for i in self.cid_user_answers.filter(exam__id=exam_pk)] [
i.answer_compare
for i in self.cid_user_answers.filter(exam__id=exam_pk)
]
) )
unmarked_answers = user_answers - self.get_marked_answers() unmarked_answers = user_answers - self.get_marked_answers()
@@ -193,24 +194,23 @@ class AnatomyQuestion(models.Model):
if i.status != i.MarkOptions.UNMARKED if i.status != i.MarkOptions.UNMARKED
] ]
) )
#correct_answers = set( # correct_answers = set(
# [i.answer.get_compare_string() for i in self.answers.all()] # [i.answer.get_compare_string() for i in self.answers.all()]
#) # )
#half_mark_answers = set( # half_mark_answers = set(
# [i.answer.get_compare_string() for i in self.half_mark_answers.all()] # [i.answer.get_compare_string() for i in self.half_mark_answers.all()]
#) # )
#incorrect_answers = set( # incorrect_answers = set(
# [i.answer.get_compare_string() for i in self.incorrect_answers.all()] # [i.answer.get_compare_string() for i in self.incorrect_answers.all()]
#) # )
#marked_answers = correct_answers | half_mark_answers | incorrect_answers # marked_answers = correct_answers | half_mark_answers | incorrect_answers
#return marked_answers # return marked_answers
def get_annotations(self): def get_annotations(self):
return self.image_annotations return self.image_annotations
@reversion.register @reversion.register
class Answer(models.Model): class Answer(models.Model):
question = models.ForeignKey( question = models.ForeignKey(
@@ -243,7 +243,7 @@ class Answer(models.Model):
self.answer = self.answer.strip() self.answer = self.answer.strip()
s = self.answer.lower() s = self.answer.lower()
s = s.translate(str.maketrans('', '', string.punctuation)) s = s.translate(str.maketrans("", "", string.punctuation))
self.answer_compare = s self.answer_compare = s
@@ -292,10 +292,12 @@ class Exam(ExamBase):
help_text="Exam time limit (in seconds)", default=5400 help_text="Exam time limit (in seconds)", default=5400
) )
author = models.ManyToManyField(settings.AUTH_USER_MODEL, author = models.ManyToManyField(
settings.AUTH_USER_MODEL,
blank=True, blank=True,
help_text='Author of exam', help_text="Author of exam",
related_name="anatomy_exam_author") related_name="anatomy_exam_author",
)
def get_exam_json(self): def get_exam_json(self):
questions = self.exam_questions.all() questions = self.exam_questions.all()
@@ -342,7 +344,11 @@ class CidUserAnswer(models.Model):
answer_compare = models.TextField(max_length=500, blank=True) answer_compare = models.TextField(max_length=500, blank=True)
cid = models.BigIntegerField(blank=True, null=True, help_text="Candidate ID (limitied by BigIntegerField size)") cid = models.BigIntegerField(
blank=True,
null=True,
help_text="Candidate ID (limitied by BigIntegerField size)",
)
# Each user answer is associated with a particular exam # Each user answer is associated with a particular exam
exam = models.ForeignKey( exam = models.ForeignKey(
@@ -370,7 +376,7 @@ class CidUserAnswer(models.Model):
self.answer = self.answer.strip() self.answer = self.answer.strip()
s = self.answer.lower() s = self.answer.lower()
s = s.translate(str.maketrans('', '', string.punctuation)) s = s.translate(str.maketrans("", "", string.punctuation))
self.answer_compare = s self.answer_compare = s
@@ -19,9 +19,6 @@ User: {{user}}
</div> </div>
{% endif %} {% endif %}
{{view.question}}
{{view.question.pk}}
<div class="fieldWrapper"> <div class="fieldWrapper">
{{ form.content_type.errors }} {{ form.content_type.errors }}
{{ form.content_type }} {{ form.content_type }}
+1
View File
@@ -213,6 +213,7 @@ class AddQuestionNote(CreateView):
"object_id" : pk } "object_id" : pk }
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# This can also be accessed via view.**** in the template
context = super(AddQuestionNote, self).get_context_data(**kwargs) context = super(AddQuestionNote, self).get_context_data(**kwargs)
context['question'] = self.question context['question'] = self.question
return context return context