Commit 94c413a1 authored by Rafael Monnerat's avatar Rafael Monnerat

lxml.html.tostring seems not work well when it has tal:block, so context...

lxml.html.tostring seems not work well when it has tal:block, so context substitution was moved to first.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33552 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6939876f
...@@ -57,10 +57,12 @@ import lxml ...@@ -57,10 +57,12 @@ import lxml
def updateCodeWithMainContent(self, html_code, div_class): def updateCodeWithMainContent(self, html_code, div_class):
main_content = """ main_content = """
<div class="%s"> <div class="%s">
<tal:block metal:define-slot="main"/> __REPLACE_MAIN_CONTENT__
</div> </div>
""" % (div_class) """ % (div_class)
document = lxml.html.fromstring(html_code) document = lxml.html.fromstring(html_code)
element = document.find_class(div_class)[0] element = document.find_class(div_class)[0]
element.getparent().replace(element, lxml.html.fromstring(main_content)) element.getparent().replace(element, lxml.html.fromstring(main_content))
return lxml.html.tostring(document, pretty_print=True) new_html_code = lxml.html.tostring(document, pretty_print=True)
return new_html_code.replace("__REPLACE_MAIN_CONTENT__",
'<tal:block metal:define-slot="main"/>')
...@@ -61,11 +61,12 @@ skin_folder = getattr(context.portal_skins, skin_folder_id)\n ...@@ -61,11 +61,12 @@ skin_folder = getattr(context.portal_skins, skin_folder_id)\n
template = context.portal_skins.erp5_development.template_theme_web_main\n template = context.portal_skins.erp5_development.template_theme_web_main\n
template_source = template.document_src()\n template_source = template.document_src()\n
template_body_top, template_body_bottom = template_source.split("<!-- SPLIT -->")\n template_body_top, template_body_bottom = template_source.split("<!-- SPLIT -->")\n
new_code_0 = html_text.replace("<body>", template_body_top)\n new_code = context.ERP5Site_updateCodeWithMainContent(html_text, main_div_class_name)\n
new_code_0 = new_code.replace("<body>", template_body_top)\n
new_code_1 = new_code_0.replace("</body>", template_body_bottom)\n new_code_1 = new_code_0.replace("</body>", template_body_bottom)\n
new_code_2 = new_code_1.replace("\'__REPLACE_CSS__\'", css_tales)\n new_code_2 = new_code_1.replace("\'__REPLACE_CSS__\'", css_tales)\n
new_code_3 = new_code_2.replace("\'__REPLACE_JS__\'", js_tales)\n final_code = new_code_2.replace("\'__REPLACE_JS__\'", js_tales)\n
final_code = context.ERP5Site_updateCodeWithMainContent(new_code_3, main_div_class_name)\n \n
\n \n
skin_folder.manage_addProduct[\'PageTemplates\'].manage_addPageTemplate(main_template_id, "Default Template")\n skin_folder.manage_addProduct[\'PageTemplates\'].manage_addPageTemplate(main_template_id, "Default Template")\n
getattr(skin_folder, main_template_id).write(final_code)\n getattr(skin_folder, main_template_id).write(final_code)\n
...@@ -124,10 +125,10 @@ return "OK"\n ...@@ -124,10 +125,10 @@ return "OK"\n
<string>_getiter_</string> <string>_getiter_</string>
<string>template_body_top</string> <string>template_body_top</string>
<string>template_body_bottom</string> <string>template_body_bottom</string>
<string>new_code</string>
<string>new_code_0</string> <string>new_code_0</string>
<string>new_code_1</string> <string>new_code_1</string>
<string>new_code_2</string> <string>new_code_2</string>
<string>new_code_3</string>
<string>final_code</string> <string>final_code</string>
<string>_getitem_</string> <string>_getitem_</string>
</tuple> </tuple>
......
58 59
\ No newline at end of file \ 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