OLD | NEW |
(Empty) | |
| 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.5 2004-03-27 00:01:48 richard Exp $ |
| 22 |
| 23 def chatty(db, cl, nodeid, newvalues): |
| 24 ''' If the issue is currently 'unread', 'resolved', 'done-cbb' or None, |
| 25 then set 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'): |
| 31 return |
| 32 |
| 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 |
| 39 |
| 40 # get the current value |
| 41 current_status = cl.get(nodeid, 'status') |
| 42 |
| 43 # see if there's an explicit change in this transaction |
| 44 if newvalues.has_key('status'): |
| 45 # yep, skip |
| 46 return |
| 47 |
| 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 |
| 55 |
| 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 + [None]: |
| 59 # yep, we're now chatting |
| 60 newvalues['status'] = chatting_id |
| 61 |
| 62 |
| 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 |
| 68 |
| 69 # get the unread state ID |
| 70 try: |
| 71 unread_id = db.status.lookup('new') |
| 72 except KeyError: |
| 73 # no unread state, ignore all this stuff |
| 74 return |
| 75 |
| 76 # ok, do it |
| 77 newvalues['status'] = unread_id |
| 78 |
| 79 |
| 80 def init(db): |
| 81 # fire before changes are made |
| 82 db.issue.audit('set', chatty) |
| 83 db.issue.audit('create', presetunread) |
| 84 db.confidential.audit('create', presetunread) |
| 85 |
| 86 # vim: set filetype=python ts=4 sw=4 et si |
| 87 #SHA: 97f4de5b9d06b6be7ea73ba639a48141c80deaf9 |
OLD | NEW |