Commit b28d6d25 by Victor Shnayder

make customtag take impl as attribute rather than child

parent ef3a34ae
...@@ -82,7 +82,6 @@ class TranslateCustomTagDescriptor(XModuleDescriptor): ...@@ -82,7 +82,6 @@ class TranslateCustomTagDescriptor(XModuleDescriptor):
xml_object = etree.fromstring(xml_data) xml_object = etree.fromstring(xml_data)
tag = xml_object.tag tag = xml_object.tag
xml_object.tag = 'customtag' xml_object.tag = 'customtag'
impl = etree.SubElement(xml_object, 'impl') xml_object.attrib['impl'] = tag
impl.text = tag
return system.process_xml(etree.tostring(xml_object)) return system.process_xml(etree.tostring(xml_object))
...@@ -21,19 +21,23 @@ class CustomTagModule(XModule): ...@@ -21,19 +21,23 @@ class CustomTagModule(XModule):
course.xml:: course.xml::
... ...
<customtag page="234"><impl>book</impl></customtag> <customtag page="234" impl="book"/>
... ...
Renders to:: Renders to::
More information given in <a href="/book/234">the text</a> More information given in <a href="/book/234">the text</a>
""" """
def __init__(self, system, location, definition, instance_state=None, shared_state=None, **kwargs): def __init__(self, system, location, definition,
XModule.__init__(self, system, location, definition, instance_state, shared_state, **kwargs) instance_state=None, shared_state=None, **kwargs):
XModule.__init__(self, system, location, definition,
instance_state, shared_state, **kwargs)
xmltree = etree.fromstring(self.definition['data']) xmltree = etree.fromstring(self.definition['data'])
template_name = xmltree.find('impl').text template_name = xmltree.attrib['impl']
params = dict(xmltree.items()) params = dict(xmltree.items())
with self.system.filestore.open('custom_tags/{name}'.format(name=template_name)) as template: with self.system.filestore.open(
'custom_tags/{name}'.format(name=template_name)) as template:
self.html = Template(template.read()).render(**params) self.html = Template(template.read()).render(**params)
def get_html(self): def get_html(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