From 973afa6eff9cbce4db8589055fd67efe27957606 Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 15 Dec 2021 18:43:51 +0000 Subject: [PATCH] . --- anatomy/models.py | 49 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/anatomy/models.py b/anatomy/models.py index b3f0a1cd..5d76859f 100644 --- a/anatomy/models.py +++ b/anatomy/models.py @@ -48,6 +48,7 @@ class Structure(models.Model): def __str__(self): return self.structure + class Region(models.Model): region = models.CharField(max_length=200) @@ -78,7 +79,10 @@ class AnatomyQuestion(models.Model): 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( blank=True, @@ -133,7 +137,11 @@ class AnatomyQuestion(models.Model): def __str__(self): # Get first answer 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 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}) def get_primary_answer(self): - if self.answers.filter(proposed=False, status=Answer.MarkOptions.CORRECT).count() > 0: - return self.answers.filter(proposed=False, status=Answer.MarkOptions.CORRECT).first().answer + if ( + self.answers.filter( + proposed=False, status=Answer.MarkOptions.CORRECT + ).count() + > 0 + ): + return ( + self.answers.filter(proposed=False, status=Answer.MarkOptions.CORRECT) + .first() + .answer + ) else: return "None yet..." @@ -241,11 +258,9 @@ class AnatomyQuestion(models.Model): if self.image_annotations: annotations.append(str(self.image_annotations)) - - json = { "images": images, - #"feedback_image": [], + # "feedback_image": [], "annotations": annotations, "type": "anatomy", "title": self.get_title(), @@ -354,7 +369,9 @@ class Exam(ExamBase): 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): questions = self.exam_questions.all() @@ -426,7 +443,9 @@ class CidUserAnswer(models.Model): updated = models.DateTimeField(auto_now=True) 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): @@ -462,12 +481,12 @@ class CidUserAnswer(models.Model): def get_answer_score(self, cached=True): if cached and self.score: - if self.score == Answer.MarkOptions.CORRECT: - mark = 2 - elif self.score == Answer.MarkOptions.HALF_MARK: - mark = 1 - elif self.score == Answer.MarkOptions.INCORRECT: - mark = 0 + if self.score == Answer.MarkOptions.CORRECT: + mark = 2 + elif self.score == Answer.MarkOptions.HALF_MARK: + mark = 1 + elif self.score == Answer.MarkOptions.INCORRECT: + mark = 0 return mark else: