Commit cbff9efd authored by Ivan Tyagov's avatar Ivan Tyagov

Use notification tool to send notification emails rather than add hoc way.

parent 49932bc5
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Notification Message" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Delete_objects_Permission</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value> <string>5975888bf63cbbf10adb9581c07c6be5</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>forum-new-thread</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>forum-new-thread</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Notification Message</string> </value>
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string encoding="cdata"><![CDATA[
<pre wrap="">\n
New forum post with subject : &quot;${subject}&quot;\n
\n
has been created at this url:\n
\n
${url}\n
\n
You are kindly invited to follow this link and log in into the system\n
and participate into the discussion.\n
\n
Kind Regards\n
${sender}\n
</pre>
]]></string> </value>
</item>
<item>
<key> <string>text_content_substitution_mapping_method_id</string> </key>
<value> <string>NotificationMessage_getSubstitutionMappingDictFromArgument</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>[ERP5] New Forum Thread</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -50,9 +50,7 @@ ...@@ -50,9 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>"""\n
"""\n
This script allows to create a new Discussion Thread.\n This script allows to create a new Discussion Thread.\n
"""\n """\n
MARKER = [\'\', None, []]\n MARKER = [\'\', None, []]\n
...@@ -103,36 +101,44 @@ discussion_post.submit()\n ...@@ -103,36 +101,44 @@ discussion_post.submit()\n
\n \n
if send_notification_text not in (\'\', None):\n if send_notification_text not in (\'\', None):\n
# we can send notifications\n # we can send notifications\n
email_list = []\n person_list = []\n
notification_list = send_notification_text.split(\'\\n\')\n notification_list = send_notification_text.split(\'\\n\')\n
for notification in notification_list:\n for notification in notification_list:\n
# XXX: proper email validation?\n # we can assume user wanted to specify Person\'s title\n
if \'@\' in notification and \'.\' in notification:\n person_list.extend(portal.portal_catalog(portal_type=\'Person\',\n
# user specified an email\n title=notification,\n
email_list.append(notification)\n default_email_text=\'!=\'))\n
else:\n if len(person_list):\n
# we can assume user wanted to specify Person\'s title\n #Get message from catalog\n
person_list = portal.portal_catalog(portal_type=\'Person\',\n notification_reference = \'forum-new-thread\'\n
title=notification)\n notification_message = context.NotificationTool_getDocumentValue(notification_reference, \'en\')\n
email_list.extend([x.getDefaultEmailText() for x in person_list])\n if notification_message is None:\n
email_from = portal.email_from_address\n raise ValueError, \'Unable to found Notification Message with reference "%s".\' % notification_reference\n
email_subject = "New forum post"\n
email_template = """\n
\n \n
New forum post has been created at this url:\n notification_mapping_dict = {\'subject\': discussion_thread.getTitle(),\n
\n \'url\': discussion_thread.absolute_url(),\n
${url}""" \n \'sender\': portal.email_from_name }\n
email_body = context.Base_translateString(email_template, mapping={\'url\':discussion_thread.absolute_url()})\n #Preserve HTML else convert to text\n
email_list = filter(lambda x: x not in (None , \'\',) and \'@\' in x, email_list)\n if notification_message.getContentType() == "text/html":\n
# XXX: use activities & portal_notifications\n mail_text = notification_message.asEntireHTML(\n
for email_to in email_list:\n substitution_method_parameter_dict={\'mapping_dict\':notification_mapping_dict})\n
context.MailHost.send(email_body, email_to, email_from, email_subject)\n else:\n
mail_text = notification_message.asText(\n
substitution_method_parameter_dict={\'mapping_dict\':notification_mapping_dict})\n
sender = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n
#Send email\n
for recipient in person_list:\n
portal.portal_notifications.sendMessage(\n
sender=sender,\n
recipient=recipient,\n
subject=notification_message.getTitle(),\n
message=mail_text,\n
message_text_format=notification_message.getContentType(),\n
store_as_event=True)\n
\n \n
return discussion_thread.Base_redirect(form_id,\n return discussion_thread.Base_redirect(form_id,\n
keep_items = dict(portal_status_message=context.Base_translateString(portal_status_message)))\n keep_items = dict(portal_status_message=context.Base_translateString(portal_status_message)))\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
......
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
<value> <value>
<list> <list>
<string>your_title</string> <string>your_title</string>
<string>your_send_notification_text</string>
<string>your_text_content</string> <string>your_text_content</string>
<string>your_captcha</string> <string>your_captcha</string>
</list> </list>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>description</string>
<string>editable</string>
<string>enabled</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_send_notification_text</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>description</string> </key>
<value> <string>Use this text area to specify email addresses or persons\' titles which should receive notification about this post\'s creation. Each on a new line. Wildcards like \'%\' are supported.</string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <int>40</int> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_text_area_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Notification list</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
95 96
\ No newline at end of file \ No newline at end of file
notification_message_module/forum-new-thread
notification_message_module/forum-new-thread/**
portal_gadgets/erp5_forum portal_gadgets/erp5_forum
portal_gadgets/erp5_forum/** portal_gadgets/erp5_forum/**
portal_skins/erp5_rss_style/ListBox_asPostStyleHTML portal_skins/erp5_rss_style/ListBox_asPostStyleHTML
\ 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