From 16990c2743fc7973dc98d8d042563f41cb3a1880 Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Wed, 24 Oct 2012 17:23:13 -0400 Subject: [PATCH] Add an end date to courses. - needed for cert generation (and later lots of other things) --- common/lib/xmodule/xmodule/course_module.py | 15 +++++++++++++-- doc/xml-format.md | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index e7e3e4e519..0a5108590f 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -22,13 +22,13 @@ class CourseDescriptor(SequenceDescriptor): self.book_url = book_url self.table_of_contents = self._get_toc_from_s3() self.start_page = int(self.table_of_contents[0].attrib['page']) - + # The last page should be the last element in the table of contents, # but it may be nested. So recurse all the way down the last element last_el = self.table_of_contents[-1] while last_el.getchildren(): last_el = last_el[-1] - + self.end_page = int(last_el.attrib['page']) @property @@ -87,6 +87,7 @@ class CourseDescriptor(SequenceDescriptor): self.enrollment_start = self._try_parse_time("enrollment_start") self.enrollment_end = self._try_parse_time("enrollment_end") + self.end = self._try_parse_time("end") # NOTE: relies on the modulestore to call set_grading_policy() right after # init. (Modulestore is in charge of figuring out where to load the policy from) @@ -127,6 +128,16 @@ class CourseDescriptor(SequenceDescriptor): return definition + def has_ended(self): + """ + Returns True if the current time is after the specified course end date. + Returns False if there is no end date specified. + """ + if self.end_date is None: + return False + + return time.gmtime() > self.end + def has_started(self): return time.gmtime() > self.start diff --git a/doc/xml-format.md b/doc/xml-format.md index ac9fbb5e40..d9c0d27653 100644 --- a/doc/xml-format.md +++ b/doc/xml-format.md @@ -251,6 +251,7 @@ Supported fields at the course level: * "start" -- specify the start date for the course. Format-by-example: "2012-09-05T12:00". * "enrollment_start", "enrollment_end" -- when can students enroll? (if not specified, can enroll anytime). Same format as "start". +* "end" -- specify the end date for the course. Format-by-example: "2012-11-05T12:00". * "tabs" -- have custom tabs in the courseware. See below for details on config. * TODO: there are others