Skip to content
Snippets Groups Projects
Commit e67dfb70 authored by Calen Pennington's avatar Calen Pennington
Browse files

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

Add categories and XModuleDescriptors for all module types that are used at the top level of a course
parent fe45de38
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ class Command(BaseCommand): ...@@ -32,7 +32,7 @@ class Command(BaseCommand):
elements = list(course.iter()) elements = list(course.iter())
tag_to_category = {# Inside HTML ==> Skip these tag_to_category = {
# Custom tags # Custom tags
'videodev': 'Custom', 'videodev': 'Custom',
'slides': 'Custom', 'slides': 'Custom',
...@@ -40,33 +40,44 @@ class Command(BaseCommand): ...@@ -40,33 +40,44 @@ class Command(BaseCommand):
'image': 'Custom', 'image': 'Custom',
'discuss': 'Custom', 'discuss': 'Custom',
# Simple lists # Simple lists
'chapter': 'Chapter', 'chapter': 'Week',
'course': 'Course', 'course': 'Course',
'sequential': 'LectureSequence', 'sequential': 'LectureSequence',
'vertical': 'ProblemSet', '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 # True types
'video': 'VideoSegment', 'video': 'VideoSegment',
'html': 'HTML', 'html': 'HTML',
'problem': 'Problem', 'problem': 'Problem',
} }
name_index = 0
name_index=0
for e in elements: for e in elements:
name = e.attrib.get('name', None) name = e.attrib.get('name', None)
for f in elements: for f in elements:
if f != e and f.attrib.get('name', None) == name: if f != e and f.attrib.get('name', None) == name:
name = None name = None
if not name: 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 name_index = name_index + 1
if e.tag in tag_to_category: if e.tag in tag_to_category:
category = tag_to_category[e.tag] category = tag_to_category[e.tag]
if isinstance(category, dict):
category = category[e.get('format')]
category = category.replace('/', '-') category = category.replace('/', '-')
name = name.replace('/', '-') name = name.replace('/', '-')
e.set('url', 'i4x://mit.edu/6002xs12/{category}/{name}'.format(category = category, e.set('url', 'i4x://mit.edu/6002xs12/{category}/{name}'.format(
name = name)) category=category,
name=name))
def handle_skip(e): def handle_skip(e):
......
...@@ -40,28 +40,19 @@ ...@@ -40,28 +40,19 @@
<header> <header>
<h1><a href="#">${week.name}</a></h1> <h1><a href="#">${week.name}</a></h1>
<ul> <ul>
<li class="goal editable"><strong>Goal title:</strong> This is a goal that will be in the header of the week</li> % for goal in week.get_goals():
<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> <li class="goal editable"><strong>${goal.name}:</strong>${goal.data}</li>
% endfor
</ul> </ul>
</header> </header>
<ul> <ul>
<li class="seq"> % for module in week.get_non_goals():
<a href="#" class="sequence-edit">Lecture Sequence</a> <li class="${module.type}">
<a href="#" class="draggable">handle</a> <a href="#" class="${module.type}-edit">${module.name}</a>
</li> <a href="#" class="draggable">handle</a>
<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>
</li> </li>
% endfor
<%include file="module-dropdown.html"/> <%include file="module-dropdown.html"/>
</ul> </ul>
</li> </li>
......
...@@ -97,9 +97,22 @@ class Module(XModule): ...@@ -97,9 +97,22 @@ class Module(XModule):
self.rendered = False self.rendered = False
class CourseModuleDescriptor(XModuleDescriptor): class WeekDescriptor(XModuleDescriptor):
pass
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 pass
...@@ -7,8 +7,15 @@ setup( ...@@ -7,8 +7,15 @@ setup(
install_requires=['distribute'], install_requires=['distribute'],
entry_points={ entry_points={
'xmodule.v1': [ 'xmodule.v1': [
"Course = seq_module:CourseModuleDescriptor", "Course = seq_module:SectionDescriptor",
"Chapter = seq_module:ChapterModuleDescriptor", "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): ...@@ -57,3 +57,7 @@ class Module(XModule):
self.annotations=[(e.get("name"),self.render_function(e)) \ self.annotations=[(e.get("name"),self.render_function(e)) \
for e in xmltree] for e in xmltree]
class VideoSegmentDescriptor(XModuleDescriptor):
pass
...@@ -152,13 +152,18 @@ class XModuleDescriptor(Plugin): ...@@ -152,13 +152,18 @@ class XModuleDescriptor(Plugin):
self.data = data if data is not None else {} self.data = data if data is not None else {}
self.children = children if children is not None else [] self.children = children if children is not None else []
self.name = Location(kwargs.get('location')).name self.name = Location(kwargs.get('location')).name
self.type = Location(kwargs.get('location')).category
self._child_instances = None 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""" """Returns a list of XModuleDescriptor instances for the children of this module"""
if self._child_instances is None: if self._child_instances is None:
self._child_instances = [self.load_item(child) for child in self.children] 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): def get_xml(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment