Commit dc4bd890 authored by Jérome Perrin's avatar Jérome Perrin

deferred_style_core: use page template to build html

instead of building HTML in python, it's cleaner and prevent problems when attachments names are HTML entities.
parent 1792f75b
......@@ -21,9 +21,14 @@ if prefs.getPreferredDeferredReportStoredAsDocument():
document.activate(tag=pre_convert_tag).convert(format=format)
url_base = portal.ERP5Site_getAbsoluteUrl()
report_url_text = '<br/>'.join([
'''<a href="%s/%s?format=%s">%s</a>''' % (url_base , report_url, format, report_name ) for (report_name, report_url) in report_item_list ])
message = '%s<br/>%s' % ( newline_to_br(html_quote(message)), report_url_text )
attachment_link_list = [
{
'download_link': '%s/%s?format=%s' % (url_base , report_url, format),
'name': report_name
} for (report_name, report_url) in report_item_list
]
message_html = newline_to_br(html_quote(message))
message_text_format = "text/html"
attachment_list = []
notification_message_reference = prefs.getPreferredDeferredReportNotificationMessageReference()
......@@ -32,11 +37,20 @@ if prefs.getPreferredDeferredReportStoredAsDocument():
if notification_message is None:
raise ValueError('Notification message not found by %r' % prefs.getPreferredDeferredReportNotificationMessageReference())
notification_mapping_dict = {
'report_link_list': report_url_text,
'report_link_list': portal.ERP5Site_viewReportCompleteNotificationMessage(
attachment_link_list=attachment_link_list
),
'message': message_html
}
message = notification_message.asEntireHTML(
safe_substitute=False,
substitution_method_parameter_dict={'mapping_dict': notification_mapping_dict})
else:
# fallback to generating message with the page template when no notification message
message = portal.ERP5Site_viewReportCompleteNotificationMessage(
attachment_link_list=attachment_link_list,
message=message_html
)
portal.portal_notifications.activate(after_tag=pre_convert_tag, activity='SQLQueue').sendMessage(
recipient=user_name,
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_viewReportCompleteNotificationMessage</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<tal:block xmlns:tal="http://xml.zope.org/namespaces/tal">
<tal:block tal:replace="nothing">
This page template is used to prepare `report_link_list` variable to pass to notification message.
When no notification message exists, this page template acts as a "default notification message" and
receive `message` argument.
</tal:block>
<tal:block tal:condition="options/message | nothing">
<p>
<tal:block tal:replace="structure options/message" />
</p>
</tal:block>
<tal:block tal:repeat="attachment options/attachment_link_list">
<p>
<a tal:attributes="href attachment/download_link" tal:content="attachment/name"></a>
</p>
</tal:block>
</tal:block>
\ 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