[Erp5-report] r13212 - in /erp5/trunk/products/ERP5: ./ Tool/ dtml/

nobody at svn.erp5.org nobody at svn.erp5.org
Sun Mar 4 13:26:17 CET 2007


Author: jp
Date: Sun Mar  4 13:26:06 2007
New Revision: 13212

URL: http://svn.erp5.org?rev=13212&view=rev
Log:
Initial and proposed implementation of Notification Tool.

Added:
    erp5/trunk/products/ERP5/Tool/NotificationTool.py
    erp5/trunk/products/ERP5/dtml/explainNotificationTool.dtml
Modified:
    erp5/trunk/products/ERP5/__init__.py

Added: erp5/trunk/products/ERP5/Tool/NotificationTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/NotificationTool.py?rev=13212&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/Tool/NotificationTool.py (added)
+++ erp5/trunk/products/ERP5/Tool/NotificationTool.py Sun Mar  4 13:26:06 2007
@@ -1,0 +1,131 @@
+##############################################################################
+#
+# Copyright (c) 2004 Nexedi SARL and Contributors. All Rights Reserved.
+#                    Sebastien Robin <seb at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+##############################################################################
+
+import time
+import threading
+
+from AccessControl import ClassSecurityInfo
+from AccessControl.SecurityManagement import newSecurityManager
+from Globals import InitializeClass, DTMLFile, PersistentMapping
+from Products.CMFCore.utils import getToolByName
+from Products.ERP5Type.Core.Folder import Folder
+from Products.ERP5Type.Tool.BaseTool import BaseTool
+from Products.ERP5Type import Permissions
+from Products.ERP5 import _dtmldir
+
+from zLOG import LOG, INFO
+
+class NotificationTool(BaseTool):
+  """
+    This tool manages notifications.
+
+    It is used as a central point to send messages from one
+    user to one or many users. The purpose of the tool
+    is to provide an API for sending messages which is
+    independent on how messages are actually going to be
+    sent and when.
+
+    It is also useful to send messages without having to
+    write always the same piece of code (eg. lookup the user,
+    lookup its mail, etc.).
+
+    This early implementation only provides asynchronous
+    email sending.
+
+    Future implementations may be able to lookup user preferences
+    to decide how and when to send a message to each user.
+  """
+  id = 'portal_notifications'
+  meta_type = 'ERP5 Notification Tool'
+  portal_type = 'Notification Tool'
+
+  # Declarative Security
+  security = ClassSecurityInfo()
+
+  security.declareProtected( Permissions.ManagePortal, 'manage_overview' )
+  manage_overview = DTMLFile( 'explainNotificationTool', _dtmldir )
+
+  security.declareProtected(Permissions.UseMailhostServices, 'sendMessage')
+  def sendMessage(self, sender=None, recipient=None, subject=None, message=None, attachment_list=None):
+    """
+      This method provides a common API to send messages to users
+      from object actions of worflow scripts.
+
+      sender -- a string or a Person object
+
+      recipient -- a string or a Person object
+                   a list of thereof
+
+      subject -- the subject of the message
+
+      message -- the text of the message (already translated)
+
+      attachment_list -- attached documents (optional)
+    """
+    catalog_tool = getToolByName(self, 'portal_catalog')
+
+    # Change all strings to object values
+    if isinstance(sender, basestring):
+      sender = catalog_tool.getObject(portal_type='Person', reference=sender)
+
+    email_from_address = None
+    if sender is not None:
+      email_value = sender.getDefaultEmailValue()
+      if email_value is not None:
+        email_from_address = email_value.asText()
+    if not email_from_address:
+      # If we can not find a from address then
+      # we fallback to portal values
+      portal = self.getPortalObject()
+      email_from_address = portal.email_from_address
+
+    # To is a list - let us find all members
+    if isinstance(recipient, basestring):
+      recipient = [recipient]
+    to_list = []
+    for user in recipient:
+      user_value = catalog_tool.getObject(portal_type='Person', reference=user)
+      if user_value is not None:
+        to_list.append(user_value)
+
+    # Default implementation is to send an active message to everyone
+    for person in to_list:
+      email_value = person.getDefaultEmailValue()
+      if email_value is not None:
+        email_value.activate(activity='SQLQueue').send(
+                                    from_url=email_from_address,
+                                    to_url=email_value.asText(),
+                                    subject=subject,
+                                    msg=message,
+                                    attachment_list=attachment_list)
+    
+    # Future implemetation could consist in implementing
+    # policies such as grouped notification (per hour, per day,
+    # per week, etc.) depending on user preferences. It
+    # also add some urgency and selection of notification
+    # tool (ex SMS vs. email)

Modified: erp5/trunk/products/ERP5/__init__.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/__init__.py?rev=13212&r1=13211&r2=13212&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/__init__.py (original)
+++ erp5/trunk/products/ERP5/__init__.py Sun Mar  4 13:26:06 2007
@@ -46,7 +46,7 @@
 # Define object classes and tools
 from Tool import CategoryTool, SimulationTool, RuleTool, IdTool, TemplateTool,\
                  TestTool, DomainTool, AlarmTool, OrderTool, DeliveryTool,\
-                 TrashTool, ContributionTool 
+                 TrashTool, ContributionTool, NotificationTool
 import ERP5Site
 object_classes = ( ERP5Site.ERP5Site,
                  )
@@ -62,6 +62,7 @@
                  DeliveryTool.DeliveryTool,
                  TrashTool.TrashTool,
                  ContributionTool.ContributionTool,
+                 NotificationTool.NotificationTool,
                 )
 content_classes = ()
 content_constructors = ()

Added: erp5/trunk/products/ERP5/dtml/explainNotificationTool.dtml
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/dtml/explainNotificationTool.dtml?rev=13212&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/dtml/explainNotificationTool.dtml (added)
+++ erp5/trunk/products/ERP5/dtml/explainNotificationTool.dtml Sun Mar  4 13:26:06 2007
@@ -1,0 +1,17 @@
+<dtml-var manage_page_header>
+<dtml-var manage_tabs>
+
+<p>Help on Notification Tool</p>
+
+This tool is useful to  manage notifications.
+
+It is used as a central point to send messages from one
+user to one or many users. The purpose of the tool
+is to provide an API for sending messages which is
+independent on how messages are actually going to be
+sent and when.
+
+This early implementation only provides asynchronous
+email sending.
+
+<dtml-var manage_page_footer>




More information about the Erp5-report mailing list