checking if an answer is complete
authorJan Szejko <janek37@gmail.com>
Mon, 22 Jan 2018 16:45:07 +0000 (17:45 +0100)
committerJan Szejko <janek37@gmail.com>
Mon, 22 Jan 2018 16:45:07 +0000 (17:45 +0100)
stage2/management/commands/stage2_mark_complete.py
stage2/models.py

index 0f239b7..3720afb 100644 (file)
@@ -9,6 +9,7 @@ class Command(BaseCommand):
     def handle(self, **options):
         assignment_count = Assignment.objects.count()
         for participant in Participant.objects.all():
-            if participant.answer_set.count() == assignment_count:
+            answers = participant.answer_set.all()
+            if len(answers) == assignment_count and all(answer.is_complete() for answer in answers):
                 participant.complete_set = True
                 participant.save()
index 37308fc..2787e75 100644 (file)
@@ -162,6 +162,16 @@ class Answer(models.Model):
             return None
         return self.mark_set.aggregate(avg=models.Avg('points'))['avg']
 
+    # unrelated to `complete' attribute, but whatever
+    def is_complete(self):
+        file_count = len(self.assignment.file_descriptions)
+        field_count = len(self.assignment.field_descriptions)
+        if self.attachment_set.count() < file_count:
+            return False
+        if self.fieldoption_set.count() + sum(1 for k, v in self.field_values.iteritems() if v) < field_count:
+            return False
+        return True
+
 
 class FieldOptionSet(models.Model):
     name = models.CharField(verbose_name=_('nazwa'), max_length=32, db_index=True)