bolded the section titles and added unittest skeleton for module

This commit is contained in:
Arthur Barrett
2013-02-26 12:15:43 -05:00
parent 1f160d6ef4
commit 18233ef0d7
4 changed files with 65 additions and 17 deletions

View File

@@ -63,26 +63,29 @@ class AnnotatableModule(XModule):
return data_attrs
def _render_annotation(self, index, el):
""" Renders an annotation element for HTML output. """
attr = {}
attr.update(self._get_annotation_class_attr(index, el))
attr.update(self._get_annotation_data_attr(index, el))
el.tag = 'span'
for key in attr.keys():
el.set(key, attr[key]['value'])
if '_delete' in attr[key] and attr[key]['_delete'] is not None:
delete_key = attr[key]['_delete']
del el.attrib[delete_key]
def _render_content(self):
""" Renders annotatable content with annotation spans and returns HTML. """
xmltree = etree.fromstring(self.content)
xmltree.tag = 'div'
index = 0
for el in xmltree.findall('.//annotation'):
el.tag = 'span'
attr = {}
attr.update(self._get_annotation_class_attr(index, el))
attr.update(self._get_annotation_data_attr(index, el))
for key in attr.keys():
el.set(key, attr[key]['value'])
if '_delete' in attr[key] and attr[key]['_delete'] is not None:
delete_key = attr[key]['_delete']
del el.attrib[delete_key]
self._render_annotation(index, el)
index += 1
return etree.tostring(xmltree, encoding='unicode')