work in progress: basic implementation of notification features

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2421 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-02-26 09:06:21 +00:00
parent 7c8489f170
commit 85d2423663
5 changed files with 99 additions and 17 deletions

View file

@ -5,7 +5,7 @@ from zope.testing.doctestunit import DocFileSuite
class Test(unittest.TestCase): class Test(unittest.TestCase):
"Basic tests for the cybertools.tracking.notify package." "Basic tests for the cybertools.tracking.comment package."
def testBasics(self): def testBasics(self):
pass pass

View file

@ -1,10 +1,31 @@
======== =============
Comments Notifications
======== =============
($Id$) ($Id$)
>>> from zope import component
>>> from cybertools.tracking.btree import TrackingStorage >>> from cybertools.tracking.btree import TrackingStorage
>>> from cybertools.tracking.comment.base import Comment >>> from cybertools.tracking.notify.base import Notification, NotificationManager
>>> component.provideAdapter(NotificationManager)
>>> comments = TrackingStorage(trackFactory=Comment) >>> notifications = TrackingStorage(trackFactory=Notification)
>>> from cybertools.tracking.notify.interfaces import INotificationManager
>>> manager = INotificationManager(notifications)
Storing and Retrieving Notifications
====================================
>>> manager.notify('obj01', 'user01', 'object_changed')
>>> ntf01 = manager.query(userName='user01')[0]
>>> ntf01
<Notification ['obj01', 1, 'user01', '...']:
{'media': ['inbox'], 'state': 'new', 'type': 'object_changed'}>
>>> print ntf01.state
new
>>> print ntf01.timingType
None

View file

@ -22,12 +22,45 @@ Base classes for a notification framework.
$Id$ $Id$
""" """
from zope.component import adapts
from zope.interface import implements from zope.interface import implements
from cybertools.tracking.btree import Track from cybertools.tracking.btree import Track
from cybertools.tracking.notify.interfaces import INotification from cybertools.tracking.interfaces import ITrackingStorage
from cybertools.tracking.notify.interfaces import INotification, INotificationManager
class NotificationManager(object):
implements(INotificationManager)
adapts(ITrackingStorage)
def __init__(self, context):
self.context = context
def notify(self, taskId, userName, ntfType, media=None, priority='info', **kw):
runId = self.context.startRun()
if media is None:
media = ['inbox']
data = dict(type=ntfType, state='new', media=media)
data.update(kw)
self.context.saveUserTrack(taskId, runId, userName, data)
def cleanUp(self, age=1, removeIgnored=False):
pass
def query(self, **kw):
return self.context.query(**kw)
class Notification(Track): class Notification(Track):
implements(INotification) implements(INotification)
typeName = 'Notification'
def __getattr__(self, attr):
if attr in INotification:
return self.data.get(attr)
raise AttributeError(attr)

View file

@ -28,10 +28,29 @@ from zope import schema
from cybertools.tracking.interfaces import ITrack from cybertools.tracking.interfaces import ITrack
class INotificationManager(Interface):
""" Provides methods for working with notifications.
Typically used as an adapter for ITrackingStorage objects.
"""
def notify(taskId, userName, type, media=None, **kw):
""" Create a notification object according to the information given.
"""
def cleanUp(age=1, removeIgnored=False):
""" Remove old (finished) runs and (done) tracks; the last change
(timeStamp) being before ``now - age`` days.
If the ``removeIgnored`` argument is True remove also tracks
in ``ignored`` state.
"""
class INotification(ITrack): class INotification(ITrack):
""" A notification carries information necessary to inform a """ A notification carries information necessary to inform a
receiver (typically a user or person, but possibly also an other receiver (typically a user or person, but possibly also another
entity) about an event. kind of entity) about an event.
The object the notification is related to is referenced via the The object the notification is related to is referenced via the
task id attribute; interdependent notifications (i.e. notifications task id attribute; interdependent notifications (i.e. notifications
that are triggered by the identical event or have been created that are triggered by the identical event or have been created
@ -40,20 +59,22 @@ class INotification(ITrack):
""" """
type = Attribute('A string (token) that specifies the ' type = Attribute('A string (token) that specifies the '
'type of the notification.') # TODO: vocabulary 'type of the notification.')
state = Attribute('A string (token) specifying the ' state = Attribute('A string (token) specifying the '
'current state of the notification.') # TODO: vocabulary 'current state of the notification.')
priority = Attribute('A string (token) specifying the '
'priority/importance of the notification.')
parent = Attribute('The id of the parent notification, i.e. the ' parent = Attribute('The id of the parent notification, i.e. the '
'notification that triggered the creation of this one. ' 'notification that triggered the creation of this one. '
'None if there is not parent notification.') 'None if there is not parent notification.')
eventType = Attribute('A string (token or title) that specifies the ' eventType = Attribute('A string (token or title) that specifies the '
'type of the event that triggered this notification.') 'type of the event that triggered this notification.')
media = Attribute('A string (token) specifying the ' media = Attribute('A collection of strings (tokens) specifying the '
'media type that will be used for presenting ' 'media types that will be used for presenting '
'the notification.') # TODO: vocabulary 'the notification.')
timingType = Attribute('A string (token) specifying the ' timingType = Attribute('A string (token) specifying the '
'type of timing that will be used for presenting ' 'type of timing that will be used for presenting '
'the notification.') # TODO: vocabulary 'the notification.')
timing = Attribute('A list of (typically) time/date values specifying ' timing = Attribute('A list of (typically) time/date values specifying '
'the time range for presentation. The possible values and ' 'the time range for presentation. The possible values and '
'their interpretation depend on the timing type.') 'their interpretation depend on the timing type.')
@ -67,4 +88,11 @@ class INotification(ITrack):
# media + timingType + timing + deliveryInfo could be combined to # media + timingType + timing + deliveryInfo could be combined to
# a `deliverySpec` attribute. # a `deliverySpec` attribute.
# TODO: Action class (type + instance); vocabulary of action types types = ('object_changed', 'object_new', 'invitation', 'assignment')
states = ('new', 'active', 'deferred', 'done', 'ignored')
priorities = ('critical', 'important', 'normal', 'info')
media = ('inbox', 'mail', 'im', 'rss')
timingTypes = ('immediate', 'hourly', 'daily', 'explicit')
actionTypes = ('accept', 'reject', 'ignore', 'note', 'delegate')
# TODO: Action class (type + instance)

View file

@ -5,7 +5,7 @@ from zope.testing.doctestunit import DocFileSuite
class Test(unittest.TestCase): class Test(unittest.TestCase):
"Basic tests for the cybertools.tracking.comment package." "Basic tests for the cybertools.tracking.notify package."
def testBasics(self): def testBasics(self):
pass pass