Commit e67dfb70 by Calen Pennington

Add categories and XModuleDescriptors for all module types that are used at the…

Add categories and XModuleDescriptors for all module types that are used at the top level of a course
parent fe45de38
......@@ -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):
......
......@@ -40,28 +40,19 @@
<header>
<h1><a href="#">${week.name}</a></h1>
<ul>
<li class="goal editable"><strong>Goal title:</strong> This is a goal that will be in the header of the week</li>
<li class="goal editable"><strong>Goal title two:</strong> This is another goal for this week so that students have two things to learn</li>
% for goal in week.get_goals():
<li class="goal editable"><strong>${goal.name}:</strong>${goal.data}</li>
% endfor
</ul>
</header>
<ul>
<li class="seq">
<a href="#" class="sequence-edit">Lecture Sequence</a>
<a href="#" class="draggable">handle</a>
</li>
<li class="seq">
<a href="#" class="sequence-edit">Lecture Sequence
<a href="#" class="draggable">handle</a>
</a></li>
<li class="lab">
<a href="#" class="lab-edit">Lab</a>
<a href="#" class="draggable">handle</a>
</li>
<li class="hw">
<a href="#">Homework</a>
<a href="#" class="draggable">handle</a>
% for module in week.get_non_goals():
<li class="${module.type}">
<a href="#" class="${module.type}-edit">${module.name}</a>
<a href="#" class="draggable">handle</a>
</li>
% endfor
<%include file="module-dropdown.html"/>
</ul>
</li>
......
......@@ -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
......@@ -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",
]
}
)
......@@ -57,3 +57,7 @@ class Module(XModule):
self.annotations=[(e.get("name"),self.render_function(e)) \
for e in xmltree]
class VideoSegmentDescriptor(XModuleDescriptor):
pass
......@@ -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):
......
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