X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/720b406bad055e68e416812153ef45b471457107..f1277e1a85a7190ab8ddf104b617e369b9ca84c5:/wtem/models.py?ds=inline diff --git a/wtem/models.py b/wtem/models.py index 90492bf..4c91392 100644 --- a/wtem/models.py +++ b/wtem/models.py @@ -20,6 +20,10 @@ class Submission(models.Model): email = models.EmailField(max_length = 100, unique = True) answers = models.CharField(max_length = 65536, null = True, blank = True) key_sent = models.BooleanField(default = False) + marks = JSONField() + + def __unicode__(self): + return ', '.join((self.last_name, self.first_name, self.email)) @classmethod def generate_key(cls): @@ -41,6 +45,24 @@ class Submission(models.Model): submission.save() return submission + def get_mark(self, user_id, exercise_id): + mark = None + user_id = str(user_id) + exercise_id = str(exercise_id) + if self.marks and user_id in self.marks: + mark = self.marks[user_id].get(exercise_id, None) + return mark + + def set_mark(self, user_id, exercise_id, mark): + user_id = str(user_id) + exercise_id = str(exercise_id) + if not self.marks: + self.marks = dict() + + self.marks.setdefault(user_id, {})[exercise_id] = mark + if mark == 'None': + del self.marks[user_id][exercise_id] + class Attachment(models.Model): submission = models.ForeignKey(Submission) @@ -49,7 +71,7 @@ class Attachment(models.Model): class Assignment(models.Model): - user = models.ForeignKey(User) + user = models.ForeignKey(User, unique = True) exercises = JSONField() def clean(self): @@ -58,3 +80,6 @@ class Assignment(models.Model): for exercise in self.exercises: if not isinstance(exercise, int) or exercise < 1: raise ValidationError(_('Invalid exercise id: %s' % exercise)) + + def __unicode__(self): + return self.user.username + ': ' + ','.join(map(str,self.exercises)) \ No newline at end of file