Commit b28d6d25 by Victor Shnayder

make customtag take impl as attribute rather than child

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