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
from fs.errors import ResourceNotFoundError
import logging
......@@ -19,16 +19,16 @@ class CourseDescriptor(SequenceDescriptor):
super(CourseDescriptor, self).__init__(system, definition, **kwargs)
try:
self.start = dateutil.parser.parse(self.metadata["start"])
self.start = time.strptime(self.metadata["start"], "%Y-%m-%dT%H:%M")
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))
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) + "'")
def has_started(self):
return datetime.now() > self.start
return time.gmtime() > self.start
@classmethod
def id_to_location(cls, course_id):
......@@ -86,7 +86,6 @@ class CourseDescriptor(SequenceDescriptor):
elif section_key == "title":
return self.metadata.get('display_name', self.name)
elif section_key == "university":
return self.metadata.get('start')
return self.location.org
elif section_key == "number":
return self.number
......
......@@ -30,9 +30,9 @@ def check_course(course_must_be_open=True, course_required=True):
course = modulestore().get_item(course_loc)
except KeyError:
raise Http404("Course not found.")
if course_must_be_open and not course.has_started():
raise Http404
raise Http404("This course has not yet started.")
del kwargs['course_id']
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