Added a start date to courses. Created a decorator to retrieve the course and check that it is open.

This commit is contained in:
Bridger Maxwell
2012-07-12 16:27:20 -04:00
parent 51d9ad1513
commit 8d7c4ad8de
4 changed files with 42 additions and 18 deletions

View File

@@ -1,3 +1,5 @@
from datetime import datetime
import dateutil.parser
from fs.errors import ResourceNotFoundError
import logging
from path import path
@@ -13,6 +15,14 @@ log = logging.getLogger(__name__)
class CourseDescriptor(SequenceDescriptor):
module_class = SequenceModule
def __init__(self, system, definition=None, **kwargs):
super(CourseDescriptor, self).__init__(system, definition, **kwargs)
self.start = dateutil.parser.parse(self.metadata["start"])
def has_started(self):
return datetime.now() > self.start
@classmethod
def id_to_location(cls, course_id):
org, course, name = course_id.split('/')
@@ -24,7 +34,7 @@ class CourseDescriptor(SequenceDescriptor):
@property
def title(self):
self.metadata['display_name']
return self.metadata['display_name']
@property
def instructors(self):
@@ -69,6 +79,7 @@ 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

View File

@@ -214,7 +214,7 @@ class XModuleDescriptor(Plugin):
# A list of metadata that this module can inherit from its parent module
inheritable_metadata = (
'graded', 'due', 'graceperiod', 'showanswer', 'rerandomize',
'graded', 'start', 'due', 'graceperiod', 'showanswer', 'rerandomize',
# This is used by the XMLModuleStore to provide for locations for static files,
# and will need to be removed when that code is removed
@@ -251,6 +251,7 @@ class XModuleDescriptor(Plugin):
display_name: The name to use for displaying this module to the user
format: The format of this module ('Homework', 'Lab', etc)
graded (bool): Whether this module is should be graded or not
start (string): The date for which this module will be available
due (string): The due date for this module
graceperiod (string): The amount of grace period to allow when enforcing the due date
showanswer (string): When to show answers for this module

View File

@@ -88,7 +88,7 @@ class XmlDescriptor(XModuleDescriptor):
# The attributes will be removed from the definition xml passed
# to definition_from_xml, and from the xml returned by definition_to_xml
metadata_attributes = ('format', 'graceperiod', 'showanswer', 'rerandomize',
'due', 'graded', 'name', 'slug')
'start', 'due', 'graded', 'name', 'slug')
# A dictionary mapping xml attribute names to functions of the value
# that return the metadata key and value