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
No related merge requests found
......@@ -50,39 +50,33 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string># context.log(\'report_section %s: %s/%s\' % (\n
# report_section_idx, context.getPath(), report_section.getFormId(),))\n
request = container.REQUEST\n
<value> <string>request = container.REQUEST\n
request.other.update(request_other)\n
\n
portal = context.getPortalObject()\n
\n
# emulate Localizer\'s __before_publishing_traverse__\n
request.form[\'LOCALIZER_LANGUAGE\'] = localizer_language\n
request.get(\'PARENTS\', []).insert(0, portal)\n
portal.Localizer(context, request)\n
with portal.Localizer.translationContext(localizer_language):\n
portal.portal_skins.changeSkin(skin_name)\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
# 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
if report_section.getFormId():\n
form = getattr(context, report_section.getFormId())\n
else:\n
form = None\n
\n
if report_section.getFormId():\n
form = getattr(context, report_section.getFormId())\n
else:\n
form = None\n
selection_name = request.get(\'prefixed_selection_name\')\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
selection_name = request.get(\'prefixed_selection_name\')\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
report_section.popReport(portal, render_prefix=render_prefix)\n
\n
report_section.popReport(portal, render_prefix=render_prefix)\n
\n
return report_section_idx, data\n
return report_section_idx, data.encode(\'utf8\').encode(\'zlib\')\n
</string> </value>
</item>
<item>
......
......@@ -59,30 +59,26 @@ request.form.update(request_form)\n
if skin_name and skin_name != \'None\': # make_query serializes None as \'None\'\n
portal.portal_skins.changeSkin(skin_name)\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
attachment_name = [x[len(\' filename=\'):] for x in (request.RESPONSE.getHeader(\n
\'content-disposition\') or \'\').split(\';\')\n
if x.startswith(\' filename=\')][0]\n
if attachment_name.startswith(\'"\'):\n
attachment_name = attachment_name[1:]\n
if attachment_name.endswith(\'"\'):\n
attachment_name = attachment_name[:-1]\n
attachment_list = (\n
{\'mime_type\': (request.RESPONSE.getHeader(\'content-type\') or \'application/octet-stream;\').split(\';\')[0],\n
\'content\': \'%s\' % report_data,\n
\'name\': attachment_name},)\n
attachment_name = [x[len(\' filename=\'):] for x in (request.RESPONSE.getHeader(\n
\'content-disposition\') or \'\').split(\';\')\n
if x.startswith(\' filename=\')][0]\n
if attachment_name.startswith(\'"\'):\n
attachment_name = attachment_name[1:]\n
if attachment_name.endswith(\'"\'):\n
attachment_name = attachment_name[:-1]\n
attachment_list = (\n
{\'mime_type\': (request.RESPONSE.getHeader(\'content-type\') or \'application/octet-stream;\').split(\';\')[0],\n
\'content\': \'%s\' % report_data,\n
\'name\': attachment_name},)\n
\n
# XXX Use notification message to improve message content\n
portal.portal_notifications.sendMessage(\n
recipient=user_name,\n
subject=str(attachment_name.rsplit(\'.\', 1)[0]),\n
message=str(translateString(\'Your report is attached.\\n\')),\n
message_text_format=\'text/plain\',\n
notifier_list=(\'Mail Message\',),\n
store_as_event=False,\n
attachment_list=attachment_list,\n
)\n
portal.ERP5Site_notifyReportComplete(\n
user_name=user_name,\n
subject=str(translateString(attachment_name.rsplit(\'.\', 1)[0])),\n
message=\'\',\n
attachment_list=attachment_list)\n
</string> </value>
</item>
<item>
......
......@@ -50,53 +50,47 @@
</item>
<item>
<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
\n
portal = context.getPortalObject()\n
ap = portal.restrictedTraverse(active_process_url)\n
N_ = portal.Base_translateString\n
\n
# emulate Localizer\'s __before_publishing_traverse__\n
request.form[\'LOCALIZER_LANGUAGE\'] = localizer_language\n
request.get(\'PARENTS\', []).insert(0, portal)\n
portal.Localizer(context, request)\n
# set the selected skin\n
portal.portal_skins.changeSkin(skin_name)\n
with portal.Localizer.translationContext(localizer_language):\n
# set the selected skin\n
portal.portal_skins.changeSkin(skin_name)\n
\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 = [r.getResult() for r in ap.getResultList()]\n
report_section_list.sort(lambda a, b:cmp(a[0], b[0]))\n
\n
def dummyReportMethod():\n
return report_section_list\n
def dummyReportMethod():\n
return report_section_list\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
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
form=portal.restrictedTraverse(form_path)))\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
if x.startswith(\' filename=\')][0]\n
if attachment_name.startswith(\'"\'):\n
attachment_name = attachment_name[1:]\n
if attachment_name.endswith(\'"\'):\n
attachment_name = attachment_name[:-1]\n
attachment_list = (\n
{\'mime_type\': (request.RESPONSE.getHeader(\'content-type\') or \'application/octet-stream;\').split(\';\')[0],\n
\'content\': \'%s\' % report_data,\n
\'name\': attachment_name},)\n
if attachment_name.startswith(\'"\'):\n
attachment_name = attachment_name[1:]\n
if attachment_name.endswith(\'"\'):\n
attachment_name = attachment_name[:-1]\n
attachment_list = (\n
{\'mime_type\': (request.RESPONSE.getHeader(\'content-type\') or \'application/octet-stream;\').split(\';\')[0],\n
\'content\': \'%s\' % report_data,\n
\'name\': attachment_name},)\n
\n
# XXX Use notification message to improve message content\n
portal.portal_notifications.sendMessage(\n
recipient=user_name,\n
portal.ERP5Site_notifyReportComplete(\n
user_name=user_name,\n
subject=title,\n
message=N_(\'Your report is attached.\\n\'),\n
message_text_format=\'text/plain\',\n
notifier_list=(\'Mail Message\',),\n
store_as_event=False,\n
attachment_list=attachment_list,\n
)\n
message=\'\',\n
attachment_list=attachment_list)\n
</string> </value>
</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>
108
109
\ 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