Commit bc2bba87 by Matthew Mongeau

Get rid of TextbookModule and TextbookDescriptor.

parent 58abdf3c
from fs.errors import ResourceNotFoundError from fs.errors import ResourceNotFoundError
import time import time
import logging import logging
from lxml import etree
from xmodule.util.decorators import lazyproperty from xmodule.util.decorators import lazyproperty
from xmodule.graders import load_grading_policy from xmodule.graders import load_grading_policy
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.seq_module import SequenceDescriptor, SequenceModule from xmodule.seq_module import SequenceDescriptor, SequenceModule
from xmodule.timeparse import parse_time, stringify_time from xmodule.timeparse import parse_time, stringify_time
from xmodule.textbook_module import TextbookDescriptor
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class CourseDescriptor(SequenceDescriptor): class CourseDescriptor(SequenceDescriptor):
module_class = SequenceModule 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): def __init__(self, system, definition=None, **kwargs):
super(CourseDescriptor, self).__init__(system, definition, **kwargs) super(CourseDescriptor, self).__init__(system, definition, **kwargs)
self.textbooks = self.definition['textbooks']
msg = None msg = None
if self.start is None: if self.start is None:
...@@ -29,6 +45,16 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -29,6 +45,16 @@ class CourseDescriptor(SequenceDescriptor):
self.enrollment_start = self._try_parse_time("enrollment_start") self.enrollment_start = self._try_parse_time("enrollment_start")
self.enrollment_end = self._try_parse_time("enrollment_end") 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): def has_started(self):
return time.gmtime() > self.start return time.gmtime() > self.start
...@@ -54,11 +80,6 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -54,11 +80,6 @@ class CourseDescriptor(SequenceDescriptor):
return grading_policy return grading_policy
@property
def textbooks(self):
return [child for child in self.get_children() if type(child) == TextbookDescriptor]
@lazyproperty @lazyproperty
def grading_context(self): def grading_context(self):
""" """
......
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
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