From 896c7daf367de4d00e2cec90de870d2f7b478953 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 18 Jun 2012 11:09:11 -0400 Subject: [PATCH] Add categories and XModuleDescriptors for all module types that are used at the top level of a course --- .../management/commands/import.py | 27 +++++++++++++------ cms/templates/widgets/navigation.html | 25 ++++++----------- common/lib/xmodule/seq_module.py | 19 ++++++++++--- common/lib/xmodule/setup.py | 11 ++++++-- common/lib/xmodule/video_module.py | 4 +++ common/lib/xmodule/x_module.py | 9 +++++-- 6 files changed, 63 insertions(+), 32 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index 3e0ccdd5e8..8b33f32b94 100644 --- a/cms/djangoapps/contentstore/management/commands/import.py +++ b/cms/djangoapps/contentstore/management/commands/import.py @@ -32,7 +32,7 @@ class Command(BaseCommand): elements = list(course.iter()) - tag_to_category = {# Inside HTML ==> Skip these + tag_to_category = { # Custom tags 'videodev': 'Custom', 'slides': 'Custom', @@ -40,33 +40,44 @@ class Command(BaseCommand): 'image': 'Custom', 'discuss': 'Custom', # Simple lists - 'chapter': 'Chapter', + 'chapter': 'Week', 'course': 'Course', 'sequential': 'LectureSequence', 'vertical': 'ProblemSet', - 'section': 'Section', + 'section': { + 'Lab': 'Lab', + 'Lecture Sequence': 'LectureSequence', + 'Homework': 'Homework', + 'Tutorial Index': 'TutorialIndex', + 'Video': 'VideoSegment', + 'Midterm': 'Exam', + 'Final': 'Exam', + None: 'Section', + }, # True types 'video': 'VideoSegment', 'html': 'HTML', 'problem': 'Problem', } - - name_index=0 + name_index = 0 for e in elements: name = e.attrib.get('name', None) for f in elements: if f != e and f.attrib.get('name', None) == name: name = None if not name: - name = "{tag}_{index}".format(tag = e.tag,index = name_index) + name = "{tag}_{index}".format(tag=e.tag, index=name_index) name_index = name_index + 1 if e.tag in tag_to_category: category = tag_to_category[e.tag] + if isinstance(category, dict): + category = category[e.get('format')] category = category.replace('/', '-') name = name.replace('/', '-') - e.set('url', 'i4x://mit.edu/6002xs12/{category}/{name}'.format(category = category, - name = name)) + e.set('url', 'i4x://mit.edu/6002xs12/{category}/{name}'.format( + category=category, + name=name)) def handle_skip(e): diff --git a/cms/templates/widgets/navigation.html b/cms/templates/widgets/navigation.html index 75d581dd73..1f75dab470 100644 --- a/cms/templates/widgets/navigation.html +++ b/cms/templates/widgets/navigation.html @@ -40,28 +40,19 @@

${week.name}

diff --git a/common/lib/xmodule/seq_module.py b/common/lib/xmodule/seq_module.py index 4ae4fb3813..91ff6d2671 100644 --- a/common/lib/xmodule/seq_module.py +++ b/common/lib/xmodule/seq_module.py @@ -97,9 +97,22 @@ class Module(XModule): self.rendered = False -class CourseModuleDescriptor(XModuleDescriptor): - pass +class WeekDescriptor(XModuleDescriptor): + + def get_goals(self): + """ + Return a list of Goal XModuleDescriptors that are children + of this Week + """ + return [child for child in self.get_children() if child.type == 'Goal'] + + def get_non_goals(self): + """ + Return a list of non-Goal XModuleDescriptors that are children of + this Week + """ + return [child for child in self.get_children() if child.type != 'Goal'] -class ChapterModuleDescriptor(XModuleDescriptor): +class SectionDescriptor(XModuleDescriptor): pass diff --git a/common/lib/xmodule/setup.py b/common/lib/xmodule/setup.py index 6a659b6852..1140037259 100644 --- a/common/lib/xmodule/setup.py +++ b/common/lib/xmodule/setup.py @@ -7,8 +7,15 @@ setup( install_requires=['distribute'], entry_points={ 'xmodule.v1': [ - "Course = seq_module:CourseModuleDescriptor", - "Chapter = seq_module:ChapterModuleDescriptor", + "Course = seq_module:SectionDescriptor", + "Week = seq_module:WeekDescriptor", + "Section = seq_module:SectionDescriptor", + "LectureSequence = seq_module:SectionDescriptor", + "Lab = seq_module:SectionDescriptor", + "Homework = seq_module:SectionDescriptor", + "TutorialIndex = seq_module:SectionDescriptor", + "Exam = seq_module:SectionDescriptor", + "VideoSegment = video_module:VideoSegmentDescriptor", ] } ) diff --git a/common/lib/xmodule/video_module.py b/common/lib/xmodule/video_module.py index 8f8a2c2ffd..d7c7f80291 100644 --- a/common/lib/xmodule/video_module.py +++ b/common/lib/xmodule/video_module.py @@ -57,3 +57,7 @@ class Module(XModule): self.annotations=[(e.get("name"),self.render_function(e)) \ for e in xmltree] + + +class VideoSegmentDescriptor(XModuleDescriptor): + pass diff --git a/common/lib/xmodule/x_module.py b/common/lib/xmodule/x_module.py index 23025df50b..3560eecbdc 100644 --- a/common/lib/xmodule/x_module.py +++ b/common/lib/xmodule/x_module.py @@ -152,13 +152,18 @@ class XModuleDescriptor(Plugin): self.data = data if data is not None else {} self.children = children if children is not None else [] self.name = Location(kwargs.get('location')).name + self.type = Location(kwargs.get('location')).category self._child_instances = None - def get_children(self): + def get_children(self, categories=None): """Returns a list of XModuleDescriptor instances for the children of this module""" if self._child_instances is None: self._child_instances = [self.load_item(child) for child in self.children] - return self._child_instances + + if categories is None: + return self._child_instances + else: + return [child for child in self._child_instances if child.type in categories] def get_xml(self):