From 9c1799e50e30312f8c1424ba81da3e82280c2b86 Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Fri, 17 Oct 2008 13:21:12 +0000
Subject: [PATCH] Use portal_notifications to send report to the user.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24227 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../Base_activateReport.xml                   |  6 +-
 .../erp5_deferred_style_core/Base_report.xml  | 78 ++++++-------------
 bt5/erp5_deferred_style/bt/revision           |  2 +-
 3 files changed, 29 insertions(+), 57 deletions(-)

diff --git a/bt5/erp5_deferred_style/SkinTemplateItem/portal_skins/erp5_deferred_style_core/Base_activateReport.xml b/bt5/erp5_deferred_style/SkinTemplateItem/portal_skins/erp5_deferred_style_core/Base_activateReport.xml
index d7f87fb07f..73fd45e4d7 100644
--- a/bt5/erp5_deferred_style/SkinTemplateItem/portal_skins/erp5_deferred_style_core/Base_activateReport.xml
+++ b/bt5/erp5_deferred_style/SkinTemplateItem/portal_skins/erp5_deferred_style_core/Base_activateReport.xml
@@ -59,7 +59,7 @@ RESPONSE =  request.RESPONSE\n
 portal = context.getPortalObject()\n
 N_ = portal.Base_translateString\n
 active_process = portal.portal_activities.newActiveProcess()\n
-email_to = \'jerome@nexedi.com\' # XXX \n
+user_name = context.portal_membership.getAuthenticatedMember().getUserName()\n
 \n
 skin_name = \'ODT\' # hardcoded for now\n
 tag = \'active-report-%s\' % random.randint(0, 1000)\n
@@ -100,7 +100,7 @@ portal.portal_simulation.activate(after_tag=tag).Base_report(\n
            title=form.getProperty(\'title\'),\n
            request_other=request_other,\n
            form_path=form.getPhysicalPath(),\n
-           email_to=email_to,\n
+           user_name=user_name,\n
           )\n
 \n
 context.activate(after_tag=tag).getTitle()\n
@@ -155,7 +155,7 @@ return context.Base_redirect(\'view\', keep_items=dict(\n
                             <string>portal</string>
                             <string>N_</string>
                             <string>active_process</string>
-                            <string>email_to</string>
+                            <string>user_name</string>
                             <string>skin_name</string>
                             <string>random</string>
                             <string>tag</string>
diff --git a/bt5/erp5_deferred_style/SkinTemplateItem/portal_skins/erp5_deferred_style_core/Base_report.xml b/bt5/erp5_deferred_style/SkinTemplateItem/portal_skins/erp5_deferred_style_core/Base_report.xml
index 7fef7fe133..70ffc2e8f4 100644
--- a/bt5/erp5_deferred_style/SkinTemplateItem/portal_skins/erp5_deferred_style_core/Base_report.xml
+++ b/bt5/erp5_deferred_style/SkinTemplateItem/portal_skins/erp5_deferred_style_core/Base_report.xml
@@ -53,9 +53,7 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string encoding="cdata"><![CDATA[
-
-request = container.REQUEST\n
+            <value> <string>request = container.REQUEST\n
 request.other.update(request_other)\n
 portal = context.getPortalObject()\n
 ap = portal.restrictedTraverse(active_process_url)\n
@@ -76,52 +74,25 @@ report_data = context.report_view.pt_render(\n
                          rendered_report_item_list=[r[1] for r in report_section_list],\n
                          form=portal.restrictedTraverse(form_path)))\n
 \n
-email_from = portal.getProperty(\'email_from_address\')\n
-if portal.getProperty(\'email_from_name\'):\n
-  email_from = \'"%s" <%s>\' % (portal.getProperty(\'email_from_name\'), email_from)\n
+attachment_list = (\n
+  {\'mime_type\': request.RESPONSE.getHeader(\'content-type\').split(\';\')[0],\n
+   \'content\': report_data,\n
+   \'name\': [x[len(\'filename=\'):] for x in request.RESPONSE.getHeader(\n
+               \'content-disposition\').split(\';\') \\\n
+               if x.startswith(\'filename=\')][0]},)\n
 \n
-if 0: # send an email ?\n
-  portal.MailHost.send(\'\'\'From:%(mfrom)s\n
-To:%(mto)s\n
-Subject:%(subject)s\n
-Content-Type: Multipart/Mixed;\n
-  boundary="Boundary-00=_GJWGGr2lsPnqbw0"\n
-\n
---Boundary-00=_GJWGGr2lsPnqbw0\n
-Content-Type: text/plain;\n
-  charset="utf-8"\n
-Content-Transfer-Encoding: 7bit\n
-Content-Disposition: inline\n
-\n
-Your report is attached.\n
-\n
-Maybe here we could sum up the parameters, date, user etc ?\n
-\n
---Boundary-00=_GJWGGr2lsPnqbw0\n
-Content-Type: application/pdf;\n
-  name="CasParticuliers.pdf"\n
-Content-Transfer-Encoding: 8bit\n
-Content-Disposition: attachment;\n
-\tfilename="%(subject)s.pdf"\n
-\n
-%(report_data)s\n
-\'\'\' % dict(subject=title,\n
-           mfrom=email_from,\n
-           mto=email_to,\n
-           report_data=report_data))\n
-\n
-# TODO: this should use portal_contributions\n
-doc = portal.document_module.newContent(portal_type=\'File\',\n
-                                  title=N_(title),\n
-                                  language=localizer_language,\n
-                                  data=report_data)\n
-\n
-content_type = request.RESPONSE.getHeader(\'Content-Type\')\n
-if content_type:\n
-  doc.setContentType(content_type.split(\';\')[0])\n
-
-
-]]></string> </value>
+# XXX Use notification message to improve message content\n
+portal.portal_notifications.sendMessage(\n
+  recipient=user_name,\n
+  subject=title,\n
+  message=\'\\nYour report is attached.\\n\\n\' \\\n
+          \'Maybe here we could sum up the parameters, date, user etc ?\\n\\n\',\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>
         </item>
         <item>
             <key> <string>_code</string> </key>
@@ -131,7 +102,7 @@ if content_type:\n
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>active_process_url, skin_name, localizer_language, title, request_other, form_path, email_to</string> </value>
+            <value> <string>active_process_url, skin_name, localizer_language, title, request_other, form_path, user_name</string> </value>
         </item>
         <item>
             <key> <string>errors</string> </key>
@@ -163,7 +134,7 @@ if content_type:\n
                             <string>title</string>
                             <string>request_other</string>
                             <string>form_path</string>
-                            <string>email_to</string>
+                            <string>user_name</string>
                             <string>_getattr_</string>
                             <string>container</string>
                             <string>request</string>
@@ -180,9 +151,10 @@ if content_type:\n
                             <string>dict</string>
                             <string>_getitem_</string>
                             <string>report_data</string>
-                            <string>email_from</string>
-                            <string>doc</string>
-                            <string>content_type</string>
+                            <string>x</string>
+                            <string>len</string>
+                            <string>attachment_list</string>
+                            <string>False</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_deferred_style/bt/revision b/bt5/erp5_deferred_style/bt/revision
index dec2bf5d61..2edeafb09d 100644
--- a/bt5/erp5_deferred_style/bt/revision
+++ b/bt5/erp5_deferred_style/bt/revision
@@ -1 +1 @@
-19
\ No newline at end of file
+20
\ No newline at end of file
-- 
2.30.9