[Erp5-report] r20823 - in /erp5/trunk/products/ERP5: Document/ Tool/
nobody at svn.erp5.org
nobody at svn.erp5.org
Sun Apr 27 19:38:16 CEST 2008
Author: jp
Date: Sun Apr 27 19:38:15 2008
New Revision: 20823
URL: http://svn.erp5.org?rev=20823&view=rev
Log:
Pseudo code added to show in which direction notification tool should evolve. Many comments and explanations.
Modified:
erp5/trunk/products/ERP5/Document/Event.py
erp5/trunk/products/ERP5/Tool/NotificationTool.py
Modified: erp5/trunk/products/ERP5/Document/Event.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Event.py?rev=20823&r1=20822&r2=20823&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Event.py (original)
+++ erp5/trunk/products/ERP5/Document/Event.py Sun Apr 27 19:38:15 2008
@@ -96,6 +96,23 @@
security.declareProtected(Permissions.AccessContentsInformation,
'getExplanationValue')
def getExplanationValue(self):
- """An event is it's own explanation
+ """
+ An event is it's own explanation
"""
return self
+
+ security.declareProtected(Permissions.UseMailhostServices, 'send')
+ def send(self, *args, **kw):
+ """
+ Make the send method overridable by typed based script
+ so that special kinds of events can use a different gateway
+ to send messages. This is useful for example to send
+ faxes through fax server or to send letters by printing
+ them to the printer or to send SMS through a custom
+ gateway. In the most usual case, sending will only consist
+ in changing the destination.
+ """
+ send_script = self._getTypeBasedMethod('send')
+ if send_script is None:
+ return self.send(*args, **kw)
+ return send_script(*args, **kw)
Modified: erp5/trunk/products/ERP5/Tool/NotificationTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/NotificationTool.py?rev=20823&r1=20822&r2=20823&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Tool/NotificationTool.py (original)
+++ erp5/trunk/products/ERP5/Tool/NotificationTool.py Sun Apr 27 19:38:15 2008
@@ -143,7 +143,9 @@
security.declareProtected(Permissions.UseMailhostServices, 'sendMessage')
def sendMessage(self, sender=None, recipient=None, subject=None,
- message=None, attachment_list=None):
+ message=None, attachment_list=None,
+ notifier_list=None, priority_level=None,
+ is_persistent=False):
"""
This method provides a common API to send messages to users
from object actions of worflow scripts.
@@ -158,6 +160,16 @@
message -- the text of the message (already translated)
attachment_list -- attached documents (optional)
+
+ priority_level -- a priority level which is used to
+ lookup user preferences and decide
+ which notifier to use
+
+ notifier_list -- a list of portal type names to use
+ to send the event
+
+ is_persistent -- whenever CRM is available, store
+ notifications as events
TODO: support default notification email
"""
@@ -216,8 +228,60 @@
raise AttributeError, \
"Can not contact the person %s" % person.getReference()
+ return
# 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
+ # also add some priority and selection of notification
# tool (ex SMS vs. email)
+
+ # Here is a sample code of how this implementation could look like
+ # (pseudo code)
+ # NOTE: this implementation should also make sure that the current
+ # buildEmailMessage method defined here and the Event.send method
+ # are merged once for all
+
+ if self.getNotifierList():
+ # CRM is installed - so we can lookup notification preferences
+ if notifier_list is None:
+ # Find which notifier to use on preferences
+ if priority_level not in ('low', 'medium', 'high'): # XXX Better naming required here
+ priority_level = 'high'
+ notifier_list = self.preferences.getPreference(
+ 'preferred_%s_priority_nofitier_list' % priority_level)
+ event_list = []
+ for notifier in notifier_list:
+ event_module = self.getDefaultModule(notifier)
+ new_event = event_module.newContent(portal_type=notifier, temp_object=is_persistent)
+ event_list.append(new_event)
+ else:
+ # CRM is not installed - only notification by email is possible
+ # So create a temp object directly
+ from Products.ERP5Type.Document import newTempEvent
+ new_event = newTempEvent(context, '_')
+ event_list = [new_event]
+
+ if event in event_list:
+ # We try to build events using the same parameters as the one
+ # we were provided for notification.
+ # The handling of attachment is still an open question:
+ # either use relation (to prevent duplication) or keep
+ # a copy inside. It is probably a good idea to
+ # make attachment_list polymorphic in order to be able
+ # to provide different kinds of attachments can be provided
+ # Either document references or binary data.
+ event.build(sender=sender, recipient=recipient, subject=subject,
+ message=message, attachment_list=attachment_list,) # Rename here and add whatever
+ # parameter makes sense such
+ # as text format
+ event.send() # Make sure workflow transition is invoked if this is
+ # a persistent notification
+
+ security.declareProtected(Permissions.AccessContentsInformation, 'getNotifierList')
+ def getNotifierList(self):
+ """
+ Returns the list of available notifiers. For now
+ we consider that any event is a potential notifier.
+ This could change though.
+ """
+ return self.getPortalEventTypeList()
More information about the Erp5-report
mailing list