+ def update_complete(self):
+ marks = self.mark_set.all()
+ if len(marks) < 2:
+ complete = False
+ need_arbiter = False
+ elif len(marks) == 2:
+ mark1, mark2 = marks
+ complete = abs(mark1.points - mark2.points) < 0.2 * self.assignment.max_points
+ need_arbiter = not complete
+ else:
+ complete = True
+ need_arbiter = False
+ self.complete = complete
+ self.need_arbiter = need_arbiter
+ self.save()
+
+ def score(self):
+ marks = self.mark_set.all()
+ if len(marks) < 2:
+ return None
+ return self.mark_set.aggregate(avg=models.Avg('points'))['avg']
+
+
+class FieldOptionSet(models.Model):
+ name = models.CharField(verbose_name=_('nazwa'), max_length=32, db_index=True)
+
+ class Meta:
+ verbose_name = _('option set')
+ verbose_name_plural = _('option sets')
+
+ def __unicode__(self):
+ return self.name
+
+ def choices(self, answer):
+ return [('', '--------')] + [
+ (option.id, option.value)
+ for option in self.fieldoption_set.extra(
+ where=['answer_id is null or answer_id = %s'],
+ params=[answer.id])]
+
+
+class FieldOption(models.Model):
+ set = models.ForeignKey(FieldOptionSet, verbose_name=_('zestaw'))
+ value = models.CharField(verbose_name=_('value'), max_length=255)
+ answer = models.ForeignKey(Answer, verbose_name=_('answer'), null=True, blank=True)
+
+ class Meta:
+ ordering = ['set', 'value']
+ verbose_name = _('option')
+ verbose_name_plural = _('options')
+
+ def __unicode__(self):
+ return self.value
+