From 945632362b410f6cccaf7279910ebd7ecb61d52d Mon Sep 17 00:00:00 2001 From: Matthew Mongeau Date: Thu, 16 Aug 2012 11:49:03 -0400 Subject: [PATCH] Get rid of TextbookModule and TextbookDescriptor. --- common/lib/xmodule/xmodule/course_module.py | 35 +++++++++++++++---- common/lib/xmodule/xmodule/textbook_module.py | 33 ----------------- 2 files changed, 28 insertions(+), 40 deletions(-) delete mode 100644 common/lib/xmodule/xmodule/textbook_module.py diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 8674b8b443..b04a0cdf69 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -1,22 +1,38 @@ from fs.errors import ResourceNotFoundError import time import logging +from lxml import etree from xmodule.util.decorators import lazyproperty from xmodule.graders import load_grading_policy from xmodule.modulestore import Location from xmodule.seq_module import SequenceDescriptor, SequenceModule from xmodule.timeparse import parse_time, stringify_time -from xmodule.textbook_module import TextbookDescriptor log = logging.getLogger(__name__) - class CourseDescriptor(SequenceDescriptor): module_class = SequenceModule + class Textbook: + def __init__(self, title, table_of_contents_url): + self.title = title + self.table_of_contents_url = table_of_contents_url + + @classmethod + def from_xml_object(cls, xml_object): + return cls(xml_object.get('title'), xml_object.get('table_of_contents_url')) + + @property + def table_of_contents(self): + raw_table_of_contents = open(self.table_of_contents_url, 'r') # TODO: This will need to come from S3 + table_of_contents = etree.parse(raw_table_of_contents).getroot() + return table_of_contents + + def __init__(self, system, definition=None, **kwargs): super(CourseDescriptor, self).__init__(system, definition, **kwargs) + self.textbooks = self.definition['textbooks'] msg = None if self.start is None: @@ -29,6 +45,16 @@ class CourseDescriptor(SequenceDescriptor): self.enrollment_start = self._try_parse_time("enrollment_start") self.enrollment_end = self._try_parse_time("enrollment_end") + @classmethod + def definition_from_xml(cls, xml_object, system): + textbooks = [] + for textbook in xml_object.findall("textbook"): + textbooks.append(cls.Textbook.from_xml_object(textbook)) + xml_object.remove(textbook) + definition = super(CourseDescriptor, cls).definition_from_xml(xml_object, system) + definition['textbooks'] = textbooks + return definition + def has_started(self): return time.gmtime() > self.start @@ -54,11 +80,6 @@ class CourseDescriptor(SequenceDescriptor): return grading_policy - @property - def textbooks(self): - return [child for child in self.get_children() if type(child) == TextbookDescriptor] - - @lazyproperty def grading_context(self): """ diff --git a/common/lib/xmodule/xmodule/textbook_module.py b/common/lib/xmodule/xmodule/textbook_module.py deleted file mode 100644 index e0d0730627..0000000000 --- a/common/lib/xmodule/xmodule/textbook_module.py +++ /dev/null @@ -1,33 +0,0 @@ -from xmodule.x_module import XModule -from xmodule.xml_module import XmlDescriptor -from lxml import etree - -class TextbookModule(XModule): - def __init__(self, system, location, definition, descriptor, instance_state=None, - shared_state=None, **kwargs): - XModule.__init__(self, system, location, definition, descriptor, - instance_state, shared_state, **kwargs) - - def get_display_items(self): - return [] - - def displayable_items(self): - return [] - -class TextbookDescriptor(XmlDescriptor): - - module_class = TextbookModule - - def __init__(self, system, definition=None, **kwargs): - super(TextbookDescriptor, self).__init__(system, definition, **kwargs) - self.title = self.metadata["title"] - - @classmethod - def definition_from_xml(cls, xml_object, system): - return { 'children': [] } - - @property - def table_of_contents(self): - raw_table_of_contents = open(self.metadata['table_of_contents_url'], 'r') # TODO: This will need to come from S3 - table_of_contents = etree.parse(raw_table_of_contents).getroot() - return table_of_contents