Mercurial > p > roundup > code
comparison templates/detectors/nosyreaction.py @ 26:c7c14960f413
Final commit of Grande Splite
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 22 Jul 2001 12:09:32 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 25:4cf1daf2f2eb | 26:c7c14960f413 |
|---|---|
| 1 #$Id: nosyreaction.py,v 1.1 2001-07-22 12:09:32 richard Exp $ | |
| 2 | |
| 3 def nosyreaction(db, cl, nodeid, oldvalues): | |
| 4 ''' A standard detector is provided that watches for additions to the | |
| 5 "messages" property. | |
| 6 | |
| 7 When a new message is added, the detector sends it to all the users on | |
| 8 the "nosy" list for the issue that are not already on the "recipients" | |
| 9 list of the message. | |
| 10 | |
| 11 Those users are then appended to the "recipients" property on the | |
| 12 message, so multiple copies of a message are never sent to the same | |
| 13 user. | |
| 14 | |
| 15 The journal recorded by the hyperdatabase on the "recipients" property | |
| 16 then provides a log of when the message was sent to whom. | |
| 17 ''' | |
| 18 messages = [] | |
| 19 if oldvalues is None: | |
| 20 # the action was a create, so use all the messages in the create | |
| 21 messages = cl.get(nodeid, 'messages') | |
| 22 elif oldvalues.has_key('messages'): | |
| 23 # the action was a set (so adding new messages to an existing issue) | |
| 24 m = {} | |
| 25 for msgid in oldvalues['messages']: | |
| 26 m[msgid] = 1 | |
| 27 messages = [] | |
| 28 # figure which of the messages now on the issue weren't there before | |
| 29 for msgid in cl.get(nodeid, 'messages'): | |
| 30 if not m.has_key(msgid): | |
| 31 messages.append(msgid) | |
| 32 if not messages: | |
| 33 return | |
| 34 | |
| 35 # send a copy to the nosy list | |
| 36 for msgid in messages: | |
| 37 cl.sendmessage(nodeid, msgid) | |
| 38 | |
| 39 # update the nosy list with the recipients from the new messages | |
| 40 nosy = cl.get(nodeid, 'nosy') | |
| 41 n = {} | |
| 42 for nosyid in nosy: n[nosyid] = 1 | |
| 43 change = 0 | |
| 44 # but don't add admin to the nosy list | |
| 45 for msgid in messages: | |
| 46 for recipid in db.msg.get(msgid, 'recipients'): | |
| 47 if recipid != '1' and not n.has_key(recipid): | |
| 48 change = 1 | |
| 49 nosy.append(recipid) | |
| 50 authid = db.msg.get(msgid, 'author') | |
| 51 if authid != '1' and not n.has_key(authid): | |
| 52 change = 1 | |
| 53 nosy.append(authid) | |
| 54 if change: | |
| 55 cl.set(nodeid, nosy=nosy) | |
| 56 | |
| 57 | |
| 58 def init(db): | |
| 59 db.issue.react('create', nosyreaction) | |
| 60 db.issue.react('set', nosyreaction) | |
| 61 | |
| 62 # | |
| 63 #$Log: not supported by cvs2svn $ | |
| 64 # |
