Commit 4f54de89 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Pseudo code added to show in which direction notification tool should evolve....

Pseudo code added to show in which direction notification tool should evolve. Many comments and explanations.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20823 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 54c19a6e
...@@ -96,6 +96,23 @@ class Event(EmailDocument, Movement): ...@@ -96,6 +96,23 @@ class Event(EmailDocument, Movement):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getExplanationValue') 'getExplanationValue')
def getExplanationValue(self): def getExplanationValue(self):
"""An event is it's own explanation """
An event is it's own explanation
""" """
return self 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)
\ No newline at end of file
...@@ -143,7 +143,9 @@ class NotificationTool(BaseTool): ...@@ -143,7 +143,9 @@ class NotificationTool(BaseTool):
security.declareProtected(Permissions.UseMailhostServices, 'sendMessage') security.declareProtected(Permissions.UseMailhostServices, 'sendMessage')
def sendMessage(self, sender=None, recipient=None, subject=None, 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 This method provides a common API to send messages to users
from object actions of worflow scripts. from object actions of worflow scripts.
...@@ -159,6 +161,16 @@ class NotificationTool(BaseTool): ...@@ -159,6 +161,16 @@ class NotificationTool(BaseTool):
attachment_list -- attached documents (optional) 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 TODO: support default notification email
""" """
catalog_tool = getToolByName(self, 'portal_catalog') catalog_tool = getToolByName(self, 'portal_catalog')
...@@ -216,8 +228,60 @@ class NotificationTool(BaseTool): ...@@ -216,8 +228,60 @@ class NotificationTool(BaseTool):
raise AttributeError, \ raise AttributeError, \
"Can not contact the person %s" % person.getReference() "Can not contact the person %s" % person.getReference()
return
# Future implemetation could consist in implementing # Future implemetation could consist in implementing
# policies such as grouped notification (per hour, per day, # policies such as grouped notification (per hour, per day,
# per week, etc.) depending on user preferences. It # 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) # 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()
\ 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