diff options
author | Prabhu Ramachandran | 2016-05-27 12:32:21 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2016-05-27 12:32:21 +0530 |
commit | 033d116bc803fe165cbe6f7e228c29d8f0b019a9 (patch) | |
tree | 6553297f4855810eb349916a4a5947a1f88c4fb2 /yaksh/models.py | |
parent | 5c74697b00ea08a2b78615637d8b322410fca4b0 (diff) | |
parent | 7b762b4550f08b95c1ebf8196bd79c3f77a306ca (diff) | |
download | online_test-033d116bc803fe165cbe6f7e228c29d8f0b019a9.tar.gz online_test-033d116bc803fe165cbe6f7e228c29d8f0b019a9.tar.bz2 online_test-033d116bc803fe165cbe6f7e228c29d8f0b019a9.zip |
Merge pull request #99 from adityacp/fix_timezone
Fix timezone
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 32fb0d0..6ee02e1 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -8,7 +8,8 @@ from django.contrib.auth.models import User from django.forms.models import model_to_dict from django.contrib.contenttypes.models import ContentType from taggit.managers import TaggableManager - +from django.utils import timezone +import pytz languages = ( ("python", "Python"), @@ -144,6 +145,8 @@ class Profile(models.Model): institute = models.CharField(max_length=128) department = models.CharField(max_length=64) position = models.CharField(max_length=64) + timezone = models.CharField(max_length=64, + choices=[(tz, tz) for tz in pytz.common_timezones]) ############################################################################### @@ -291,12 +294,14 @@ class Quiz(models.Model): # The start date of the quiz. start_date_time = models.DateTimeField("Start Date and Time of the quiz", - default=datetime.now(), + default=timezone.now(), null=True) # The end date and time of the quiz end_date_time = models.DateTimeField("End Date and Time of the quiz", - default=datetime(2199, 1, 1, 0, 0, 0, 0), + default=datetime(2199, 1, 1, + tzinfo=pytz.timezone\ + (timezone.get_current_timezone_name())), null=True) # This is always in minutes. @@ -331,7 +336,7 @@ class Quiz(models.Model): def is_expired(self): - return not self.start_date_time <= datetime.now() < self.end_date_time + return not self.start_date_time <= timezone.now() < self.end_date_time def has_prerequisite(self): return True if self.prerequisite else False @@ -409,7 +414,7 @@ class QuestionPaper(models.Model): last_attempt = AnswerPaper.objects.get_user_last_attempt(user=user, questionpaper=self) if last_attempt: - time_lag = (datetime.today() - last_attempt.start_time).days + time_lag = (datetime.today() - last_attempt.start_time.replace(tzinfo=None)).days return time_lag >= self.quiz.time_between_attempts else: return True |