This commit is contained in:
Ross
2021-12-15 18:43:51 +00:00
parent 20be0d69d1
commit 973afa6eff
+34 -15
View File
@@ -48,6 +48,7 @@ class Structure(models.Model):
def __str__(self): def __str__(self):
return self.structure return self.structure
class Region(models.Model): class Region(models.Model):
region = models.CharField(max_length=200) region = models.CharField(max_length=200)
@@ -78,7 +79,10 @@ class AnatomyQuestion(models.Model):
QuestionType, on_delete=models.SET_NULL, null=True, default=1 QuestionType, on_delete=models.SET_NULL, null=True, default=1
) )
image = models.ImageField(upload_to=image_directory_path, help_text="The image to use for the question. Ideally use use unmarked images and annotate (arrow) them on the test system. If you wish to reuse an image that is already uploaded 'clone' the question that contains it.As a preference") image = models.ImageField(
upload_to=image_directory_path,
help_text="The image to use for the question. Ideally use use unmarked images and annotate (arrow) them on the test system. If you wish to reuse an image that is already uploaded 'clone' the question that contains it.As a preference",
)
image_annotations = models.TextField( image_annotations = models.TextField(
blank=True, blank=True,
@@ -133,7 +137,11 @@ class AnatomyQuestion(models.Model):
def __str__(self): def __str__(self):
# Get first answer # Get first answer
return "{}/{}: {} [{}, {}]".format( return "{}/{}: {} [{}, {}]".format(
self.pk, self.question_type, self.get_primary_answer(), self.modality, self.structure self.pk,
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)
@@ -150,8 +158,17 @@ class AnatomyQuestion(models.Model):
return reverse("anatomy:question_detail", kwargs={"pk": self.pk}) return reverse("anatomy:question_detail", kwargs={"pk": self.pk})
def get_primary_answer(self): def get_primary_answer(self):
if self.answers.filter(proposed=False, status=Answer.MarkOptions.CORRECT).count() > 0: if (
return self.answers.filter(proposed=False, status=Answer.MarkOptions.CORRECT).first().answer self.answers.filter(
proposed=False, status=Answer.MarkOptions.CORRECT
).count()
> 0
):
return (
self.answers.filter(proposed=False, status=Answer.MarkOptions.CORRECT)
.first()
.answer
)
else: else:
return "None yet..." return "None yet..."
@@ -241,11 +258,9 @@ class AnatomyQuestion(models.Model):
if self.image_annotations: if self.image_annotations:
annotations.append(str(self.image_annotations)) annotations.append(str(self.image_annotations))
json = { json = {
"images": images, "images": images,
#"feedback_image": [], # "feedback_image": [],
"annotations": annotations, "annotations": annotations,
"type": "anatomy", "type": "anatomy",
"title": self.get_title(), "title": self.get_title(),
@@ -354,7 +369,9 @@ class Exam(ExamBase):
related_name="anatomy_exam_author", related_name="anatomy_exam_author",
) )
valid_users = models.ManyToManyField(CidUser, blank=True, related_name="anatomy_exams") valid_users = models.ManyToManyField(
CidUser, blank=True, related_name="anatomy_exams"
)
def get_exam_json(self, based=True): def get_exam_json(self, based=True):
questions = self.exam_questions.all() questions = self.exam_questions.all()
@@ -426,7 +443,9 @@ class CidUserAnswer(models.Model):
updated = models.DateTimeField(auto_now=True) updated = models.DateTimeField(auto_now=True)
score = models.CharField( score = models.CharField(
max_length=1, choices=Answer.MarkOptions.choices, default=Answer.MarkOptions.UNMARKED max_length=1,
choices=Answer.MarkOptions.choices,
default=Answer.MarkOptions.UNMARKED,
) )
def __str__(self): def __str__(self):
@@ -462,12 +481,12 @@ class CidUserAnswer(models.Model):
def get_answer_score(self, cached=True): def get_answer_score(self, cached=True):
if cached and self.score: if cached and self.score:
if self.score == Answer.MarkOptions.CORRECT: if self.score == Answer.MarkOptions.CORRECT:
mark = 2 mark = 2
elif self.score == Answer.MarkOptions.HALF_MARK: elif self.score == Answer.MarkOptions.HALF_MARK:
mark = 1 mark = 1
elif self.score == Answer.MarkOptions.INCORRECT: elif self.score == Answer.MarkOptions.INCORRECT:
mark = 0 mark = 0
return mark return mark
else: else: