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.3 2002-10-11 01:26:05 richard Exp $
23 def chatty(db, cl, nodeid, newvalues):
24 ''' If the issue is currently 'unread', 'resolved' or 'done-cbb', 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 # get the chatting state ID
34 try:
35 chatting_id = db.status.lookup('chatting')
36 except KeyError:
37 # no chatting state, ignore all this stuff
38 return
40 # get the current value
41 current_status = cl.get(nodeid, 'status')
43 # see if there's an explicit change in this transaction
44 if newvalues.has_key('status') and newvalues['status'] != current_status:
45 # yep, skip
46 return
48 # determine the id of 'unread', 'resolved' and 'chatting'
49 fromstates = []
50 for state in 'unread resolved done-cbb'.split():
51 try:
52 fromstates.append(db.status.lookup(state))
53 except KeyError:
54 pass
56 # ok, there's no explicit change, so check if we are in a state that
57 # should be changed
58 if current_status in fromstates:
59 # yep, we're now chatting
60 newvalues['status'] = chatting_id
63 def presetunread(db, cl, nodeid, newvalues):
64 ''' Make sure the status is set on new issues
65 '''
66 if newvalues.has_key('status') and newvalues['status']:
67 return
69 # ok, do it
70 newvalues['status'] = db.status.lookup('unread')
73 def init(db):
74 # fire before changes are made
75 db.issue.audit('set', chatty)
76 db.issue.audit('create', presetunread)
78 # vim: set filetype=python ts=4 sw=4 et si