X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/ca5ba2a8976e5401291150a0c3fbc9b1a3fb5f95..a87786b8abce90bf32e1950b7fe2ea41ccf52ad5:/wtem/models.py?ds=inline diff --git a/wtem/models.py b/wtem/models.py index 1e3eb4d..1cd87f9 100644 --- a/wtem/models.py +++ b/wtem/models.py @@ -1,14 +1,19 @@ import random import string +import os from django.db import models from django.contrib.auth.models import User from django.core.exceptions import ValidationError +from django.utils import simplejson from django.utils.translation import ugettext as _ from jsonfield import JSONField from contact.models import Contact +f = file(os.path.dirname(__file__) + '/fixtures/exercises.json') +exercises = simplejson.loads(f.read()) +f.close() DEBUG_KEY = '12345' @@ -20,6 +25,8 @@ 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)) @@ -43,10 +50,28 @@ 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) - name = models.CharField(max_length=100) + exercise_id = models.IntegerField() file = models.FileField(upload_to = 'wtem/attachment')