Commit 264e324c by Bridger Maxwell

Changed format of start date parsing to ISO 8601

parent f9de9623
from datetime import datetime, date import time
import dateutil.parser import dateutil.parser
from fs.errors import ResourceNotFoundError from fs.errors import ResourceNotFoundError
import logging import logging
...@@ -19,16 +19,16 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -19,16 +19,16 @@ class CourseDescriptor(SequenceDescriptor):
super(CourseDescriptor, self).__init__(system, definition, **kwargs) super(CourseDescriptor, self).__init__(system, definition, **kwargs)
try: try:
self.start = dateutil.parser.parse(self.metadata["start"]) self.start = time.strptime(self.metadata["start"], "%Y-%m-%dT%H:%M")
except KeyError: except KeyError:
self.start = date.fromtimestamp(0) #The epoch self.start = time.gmtime(0) #The epoch
log.critical("Course loaded without a start date. " + str(self.id)) log.critical("Course loaded without a start date. " + str(self.id))
except ValueError, e: except ValueError, e:
self.start = date.fromtimestamp(0) #The epoch self.start = time.gmtime(0) #The epoch
log.critical("Course loaded with a bad start date. " + str(self.id) + " '" + str(e) + "'") log.critical("Course loaded with a bad start date. " + str(self.id) + " '" + str(e) + "'")
def has_started(self): def has_started(self):
return datetime.now() > self.start return time.gmtime() > self.start
@classmethod @classmethod
def id_to_location(cls, course_id): def id_to_location(cls, course_id):
...@@ -86,7 +86,6 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -86,7 +86,6 @@ class CourseDescriptor(SequenceDescriptor):
elif section_key == "title": elif section_key == "title":
return self.metadata.get('display_name', self.name) return self.metadata.get('display_name', self.name)
elif section_key == "university": elif section_key == "university":
return self.metadata.get('start')
return self.location.org return self.location.org
elif section_key == "number": elif section_key == "number":
return self.number return self.number
......
...@@ -30,9 +30,9 @@ def check_course(course_must_be_open=True, course_required=True): ...@@ -30,9 +30,9 @@ def check_course(course_must_be_open=True, course_required=True):
course = modulestore().get_item(course_loc) course = modulestore().get_item(course_loc)
except KeyError: except KeyError:
raise Http404("Course not found.") raise Http404("Course not found.")
if course_must_be_open and not course.has_started(): if course_must_be_open and not course.has_started():
raise Http404 raise Http404("This course has not yet started.")
del kwargs['course_id'] del kwargs['course_id']
kwargs['course'] = course kwargs['course'] = course
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment