Commit 315b7514 authored by Rafael Monnerat's avatar Rafael Monnerat

If class is not found raise some good message with information.

Keep the id of the div element.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33598 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0691c1a3
......@@ -61,8 +61,15 @@ def updateCodeWithMainContent(self, html_code, div_class):
</div>
""" % (div_class)
document = lxml.html.fromstring(html_code)
element = document.find_class(div_class)[0]
element.getparent().replace(element, lxml.html.fromstring(main_content))
element_list = document.find_class(div_class)
if len(element_list) == 0:
raise ValueError("It was not possible to find div with class=%s" % (div_class))
element = element_list[0]
new_element = lxml.html.fromstring(main_content)
if element.get("id") is not None:
new_element.set('id', element.get('id'))
element.getparent().replace(element, new_element)
new_html_code = lxml.html.tostring(document, pretty_print=True)
return new_html_code.replace("__REPLACE_MAIN_CONTENT__",
'<tal:block metal:define-slot="main"/>')
62
\ No newline at end of file
64
\ No newline at end of file
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