X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/b154d06ff9d6b7fa711607bc02d03fb9db5c6d33..720b406bad055e68e416812153ef45b471457107:/wtem/models.py diff --git a/wtem/models.py b/wtem/models.py index 4a42c30..90492bf 100644 --- a/wtem/models.py +++ b/wtem/models.py @@ -2,10 +2,16 @@ import random import string from django.db import models +from django.contrib.auth.models import User +from django.core.exceptions import ValidationError +from django.utils.translation import ugettext as _ +from jsonfield import JSONField from contact.models import Contact +DEBUG_KEY = '12345' + class Submission(models.Model): contact = models.ForeignKey(Contact, null = True) key = models.CharField(max_length = 30, unique = True) @@ -13,11 +19,12 @@ class Submission(models.Model): last_name = models.CharField(max_length = 100) email = models.EmailField(max_length = 100, unique = True) answers = models.CharField(max_length = 65536, null = True, blank = True) + key_sent = models.BooleanField(default = False) @classmethod def generate_key(cls): key = '' - while not key and key in [record['key'] for record in cls.objects.values('key')]: + while not key or key in [record['key'] for record in cls.objects.values('key')]: key = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(30)) return key @@ -38,4 +45,16 @@ class Submission(models.Model): class Attachment(models.Model): submission = models.ForeignKey(Submission) name = models.CharField(max_length=100) - file = models.FileField(upload_to = 'wtem/attachment') \ No newline at end of file + file = models.FileField(upload_to = 'wtem/attachment') + + +class Assignment(models.Model): + user = models.ForeignKey(User) + exercises = JSONField() + + def clean(self): + if not isinstance(self.exercises, list): + raise ValidationError(_('Assigned exercises must be declared in a list format')) + for exercise in self.exercises: + if not isinstance(exercise, int) or exercise < 1: + raise ValidationError(_('Invalid exercise id: %s' % exercise))