Commit 46da672b authored by Jérome Perrin's avatar Jérome Perrin

various improvements to erp5_deferred_style

* use translationContext instead of low level hacks
* introduce a script ERP5Site_notifyReportComplete to do the actual notification
* do not activate a useless getTitle
* store strings encoded as zlib to prevent database growth
parent 06fe8a95
...@@ -50,39 +50,33 @@ ...@@ -50,39 +50,33 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string># context.log(\'report_section %s: %s/%s\' % (\n <value> <string>request = container.REQUEST\n
# report_section_idx, context.getPath(), report_section.getFormId(),))\n
request = container.REQUEST\n
request.other.update(request_other)\n request.other.update(request_other)\n
\n \n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
# emulate Localizer\'s __before_publishing_traverse__\n with portal.Localizer.translationContext(localizer_language):\n
request.form[\'LOCALIZER_LANGUAGE\'] = localizer_language\n portal.portal_skins.changeSkin(skin_name)\n
request.get(\'PARENTS\', []).insert(0, portal)\n
portal.Localizer(context, request)\n
\n \n
portal.portal_skins.changeSkin(skin_name)\n # for unicode encoding\n
request.RESPONSE.setHeader("Content-Type", "application/xml; charset=utf-8")\n
render_prefix = \'x%s\' % report_section_idx\n
report_section.pushReport(portal, render_prefix=render_prefix)\n
\n \n
# for unicode encoding\n if report_section.getFormId():\n
request.RESPONSE.setHeader("Content-Type", "application/xml; charset=utf-8")\n form = getattr(context, report_section.getFormId())\n
render_prefix = \'x%s\' % report_section_idx\n else:\n
report_section.pushReport(portal, render_prefix=render_prefix)\n form = None\n
\n \n
if report_section.getFormId():\n selection_name = request.get(\'prefixed_selection_name\')\n
form = getattr(context, report_section.getFormId())\n data = context.render_report_section.pt_render(\n
else:\n extra_context=dict(form=form,\n
form = None\n report_section=report_section,\n
render_prefix=render_prefix))\n
\n \n
selection_name = request.get(\'prefixed_selection_name\')\n report_section.popReport(portal, render_prefix=render_prefix)\n
data = context.render_report_section.pt_render(\n
extra_context=dict(form=form,\n
report_section=report_section,\n
render_prefix=render_prefix))\n
\n \n
report_section.popReport(portal, render_prefix=render_prefix)\n return report_section_idx, data.encode(\'utf8\').encode(\'zlib\')\n
\n
return report_section_idx, data\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -59,30 +59,26 @@ request.form.update(request_form)\n ...@@ -59,30 +59,26 @@ request.form.update(request_form)\n
if skin_name and skin_name != \'None\': # make_query serializes None as \'None\'\n if skin_name and skin_name != \'None\': # make_query serializes None as \'None\'\n
portal.portal_skins.changeSkin(skin_name)\n portal.portal_skins.changeSkin(skin_name)\n
\n \n
report_data = getattr(context, deferred_style_dialog_method)(**params)\n with portal.Localizer.translationContext(localizer_language):\n
report_data = getattr(context, deferred_style_dialog_method)(**params)\n
\n \n
attachment_name = [x[len(\' filename=\'):] for x in (request.RESPONSE.getHeader(\n attachment_name = [x[len(\' filename=\'):] for x in (request.RESPONSE.getHeader(\n
\'content-disposition\') or \'\').split(\';\')\n \'content-disposition\') or \'\').split(\';\')\n
if x.startswith(\' filename=\')][0]\n if x.startswith(\' filename=\')][0]\n
if attachment_name.startswith(\'"\'):\n if attachment_name.startswith(\'"\'):\n
attachment_name = attachment_name[1:]\n attachment_name = attachment_name[1:]\n
if attachment_name.endswith(\'"\'):\n if attachment_name.endswith(\'"\'):\n
attachment_name = attachment_name[:-1]\n attachment_name = attachment_name[:-1]\n
attachment_list = (\n attachment_list = (\n
{\'mime_type\': (request.RESPONSE.getHeader(\'content-type\') or \'application/octet-stream;\').split(\';\')[0],\n {\'mime_type\': (request.RESPONSE.getHeader(\'content-type\') or \'application/octet-stream;\').split(\';\')[0],\n
\'content\': \'%s\' % report_data,\n \'content\': \'%s\' % report_data,\n
\'name\': attachment_name},)\n \'name\': attachment_name},)\n
\n \n
# XXX Use notification message to improve message content\n portal.ERP5Site_notifyReportComplete(\n
portal.portal_notifications.sendMessage(\n user_name=user_name,\n
recipient=user_name,\n subject=str(translateString(attachment_name.rsplit(\'.\', 1)[0])),\n
subject=str(attachment_name.rsplit(\'.\', 1)[0]),\n message=\'\',\n
message=str(translateString(\'Your report is attached.\\n\')),\n attachment_list=attachment_list)\n
message_text_format=\'text/plain\',\n
notifier_list=(\'Mail Message\',),\n
store_as_event=False,\n
attachment_list=attachment_list,\n
)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -50,53 +50,47 @@ ...@@ -50,53 +50,47 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>request = container.REQUEST\n <value> <string>from Products.ERP5Type.Message import translateString\n
\n
request = container.REQUEST\n
request.other.update(request_other)\n request.other.update(request_other)\n
\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
ap = portal.restrictedTraverse(active_process_url)\n ap = portal.restrictedTraverse(active_process_url)\n
N_ = portal.Base_translateString\n
\n \n
# emulate Localizer\'s __before_publishing_traverse__\n with portal.Localizer.translationContext(localizer_language):\n
request.form[\'LOCALIZER_LANGUAGE\'] = localizer_language\n # set the selected skin\n
request.get(\'PARENTS\', []).insert(0, portal)\n portal.portal_skins.changeSkin(skin_name)\n
portal.Localizer(context, request)\n
# set the selected skin\n
portal.portal_skins.changeSkin(skin_name)\n
\n \n
report_section_list = [r.getResult() for r in ap.getResultList()]\n report_section_list = [r.getResult() for r in ap.getResultList()]\n
report_section_list.sort(lambda a, b:cmp(a[0], b[0]))\n report_section_list.sort(lambda a, b:cmp(a[0], b[0]))\n
\n \n
def dummyReportMethod():\n def dummyReportMethod():\n
return report_section_list\n return report_section_list\n
\n \n
report_data = context.restrictedTraverse(form_path).report_view.pt_render(\n report_data = context.restrictedTraverse(form_path).report_view.pt_render(\n
extra_context=dict(options={\'format\': format},\n extra_context=dict(options={\'format\': format},\n
rendered_report_item_list=[r[1] for r in report_section_list],\n rendered_report_item_list=[r[1].decode(\'zlib\') for r in report_section_list],\n
report_method=dummyReportMethod,\n report_method=dummyReportMethod,\n
form=portal.restrictedTraverse(form_path)))\n form=portal.restrictedTraverse(form_path)))\n
\n \n
attachment_name = [x[len(\' filename=\'):] for x in (request.RESPONSE.getHeader(\n attachment_name = [x[len(\' filename=\'):] for x in (request.RESPONSE.getHeader(\n
\'content-disposition\') or \'\').split(\';\')\n \'content-disposition\') or \'\').split(\';\')\n
if x.startswith(\' filename=\')][0]\n if x.startswith(\' filename=\')][0]\n
if attachment_name.startswith(\'"\'):\n if attachment_name.startswith(\'"\'):\n
attachment_name = attachment_name[1:]\n attachment_name = attachment_name[1:]\n
if attachment_name.endswith(\'"\'):\n if attachment_name.endswith(\'"\'):\n
attachment_name = attachment_name[:-1]\n attachment_name = attachment_name[:-1]\n
attachment_list = (\n attachment_list = (\n
{\'mime_type\': (request.RESPONSE.getHeader(\'content-type\') or \'application/octet-stream;\').split(\';\')[0],\n {\'mime_type\': (request.RESPONSE.getHeader(\'content-type\') or \'application/octet-stream;\').split(\';\')[0],\n
\'content\': \'%s\' % report_data,\n \'content\': \'%s\' % report_data,\n
\'name\': attachment_name},)\n \'name\': attachment_name},)\n
\n \n
# XXX Use notification message to improve message content\n portal.ERP5Site_notifyReportComplete(\n
portal.portal_notifications.sendMessage(\n user_name=user_name,\n
recipient=user_name,\n
subject=title,\n subject=title,\n
message=N_(\'Your report is attached.\\n\'),\n message=\'\',\n
message_text_format=\'text/plain\',\n attachment_list=attachment_list)\n
notifier_list=(\'Mail Message\',),\n
store_as_event=False,\n
attachment_list=attachment_list,\n
)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<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_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<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>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
\n
portal.portal_notifications.activate(queue=\'SQLQueue\').sendMessage(\n
recipient=user_name,\n
subject=subject,\n
message=message,\n
message_text_format=\'text/plain\',\n
notifier_list=(\'Site Message\',),\n
store_as_event=True,\n
attachment_list=attachment_list,\n
)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>user_name, subject, message, attachment_list</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_notifyReportComplete</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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