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()
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)