Code

Sorry about this huge checkin! It's fixing a lot of related stuff in one go
[roundup.git] / roundup / templates / classic / detectors / statusauditor.py
1 # Copyright (c) 2002 ekit.com Inc (http://www.ekit-inc.com/)
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9 #
10 #   The above copyright notice and this permission notice shall be included in
11 #   all copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
20 #
21 #$Id: statusauditor.py,v 1.1 2002-05-29 01:16:17 richard Exp $
23 def chatty(db, cl, nodeid, newvalues):
24     ''' If the issue is currently 'unread' or 'resolved', then set
25         it to 'chatting'
26     '''
27     # don't fire if there's no new message (ie. chat)
28     if not newvalues.has_key('messages'):
29         return
30     if newvalues['messages'] == cl.get(nodeid, 'messages', cache=0):
31         return
33     # determine the id of 'unread', 'resolved' and 'chatting'
34     unread_id = db.status.lookup('unread')
35     resolved_id = db.status.lookup('resolved')
36     chatting_id = db.status.lookup('chatting')
38     # get the current value
39     current_status = cl.get(nodeid, 'status')
41     # see if there's an explicit change in this transaction
42     if newvalues.has_key('status') and newvalues['status'] != current_status:
43         # yep, skip
44         return
46     # ok, there's no explicit change, so do it manually
47     if current_status in (unread_id, resolved_id):
48         newvalues['status'] = chatting_id
51 def presetunread(db, cl, nodeid, newvalues):
52     ''' Make sure the status is set on new issues
53     '''
54     if newvalues.has_key('status'):
55         return
57     # ok, do it
58     newvalues['status'] = db.status.lookup('unread')
61 def init(db):
62     # fire before changes are made
63     db.issue.audit('set', chatty)
64     db.issue.audit('create', presetunread)
66 #
67 #$Log: not supported by cvs2svn $
68 #