Commit f52c67045c989a82d17c0ccfc251ca16e6803bd8

Authored by Rohan Rangray
Exists in master

Merge branch 'master' of https://git.ucsd.edu/110swag/flashy-backend

Showing 1 changed file Side-by-side Diff

flashcards/serializers.py View file @ f52c670
1 1 from django.utils.datetime_safe import datetime
  2 +import pytz
2 3 from flashcards.models import Section, LecturePeriod, User, Flashcard
3 4 from flashcards.validators import FlashcardMask, OverlapIntervalException
4 5 from rest_framework import serializers
5 6  
... ... @@ -116,9 +117,11 @@
116 117 mask = MaskFieldSerializer()
117 118  
118 119 def validate_material_date(self, value):
  120 + utc = pytz.UTC
119 121 # TODO: make this dynamic
120   - quarter_start = datetime(2015, 3, 15)
121   - quarter_end = datetime(2015, 6, 15)
  122 + quarter_start = utc.localize(datetime(2015, 3, 15))
  123 + quarter_end = utc.localize(datetime(2015, 6, 15))
  124 +
122 125 if quarter_start <= value <= quarter_end:
123 126 return value
124 127 else:
... ... @@ -135,11 +138,6 @@
135 138 if value > datetime.now():
136 139 raise serializers.ValidationError("Invalid creation date for the Flashcard")
137 140 return value
138   -
139   - def validate_section(self, value):
140   - if Section.objects.filter(pk=value).count() > 0:
141   - return value
142   - raise serializers.ValidationError("Invalid section for the flashcard")
143 141  
144 142 def validate_text(self, value):
145 143 if len(value) > 255: