paul@2 | 1 | # Copyright (c) 2002 ekit.com Inc (http://www.ekit-inc.com/) |
paul@2 | 2 | # |
paul@2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
paul@2 | 4 | # of this software and associated documentation files (the "Software"), to deal |
paul@2 | 5 | # in the Software without restriction, including without limitation the rights |
paul@2 | 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
paul@2 | 7 | # copies of the Software, and to permit persons to whom the Software is |
paul@2 | 8 | # furnished to do so, subject to the following conditions: |
paul@2 | 9 | # |
paul@2 | 10 | # The above copyright notice and this permission notice shall be included in |
paul@2 | 11 | # all copies or substantial portions of the Software. |
paul@2 | 12 | # |
paul@2 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
paul@2 | 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
paul@2 | 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
paul@2 | 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
paul@2 | 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
paul@2 | 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
paul@2 | 19 | # SOFTWARE. |
paul@2 | 20 | # |
paul@2 | 21 | #$Id: statusauditor.py,v 1.5 2004-03-27 00:01:48 richard Exp $ |
paul@2 | 22 | |
paul@2 | 23 | def chatty(db, cl, nodeid, newvalues): |
paul@2 | 24 | ''' If the issue is currently 'unread', 'resolved', 'done-cbb' or None, |
paul@2 | 25 | then set it to 'chatting' |
paul@2 | 26 | ''' |
paul@2 | 27 | # don't fire if there's no new message (ie. chat) |
paul@2 | 28 | if not newvalues.has_key('messages'): |
paul@2 | 29 | return |
paul@2 | 30 | if newvalues['messages'] == cl.get(nodeid, 'messages'): |
paul@2 | 31 | return |
paul@2 | 32 | |
paul@2 | 33 | # get the chatting state ID |
paul@2 | 34 | try: |
paul@2 | 35 | chatting_id = db.status.lookup('chatting') |
paul@2 | 36 | except KeyError: |
paul@2 | 37 | # no chatting state, ignore all this stuff |
paul@2 | 38 | return |
paul@2 | 39 | |
paul@2 | 40 | # get the current value |
paul@2 | 41 | current_status = cl.get(nodeid, 'status') |
paul@2 | 42 | |
paul@2 | 43 | # see if there's an explicit change in this transaction |
paul@2 | 44 | if newvalues.has_key('status'): |
paul@2 | 45 | # yep, skip |
paul@2 | 46 | return |
paul@2 | 47 | |
paul@2 | 48 | # determine the id of 'unread', 'resolved' and 'chatting' |
paul@2 | 49 | fromstates = [] |
paul@2 | 50 | for state in 'unread resolved done-cbb'.split(): |
paul@2 | 51 | try: |
paul@2 | 52 | fromstates.append(db.status.lookup(state)) |
paul@2 | 53 | except KeyError: |
paul@2 | 54 | pass |
paul@2 | 55 | |
paul@2 | 56 | # ok, there's no explicit change, so check if we are in a state that |
paul@2 | 57 | # should be changed |
paul@2 | 58 | if current_status in fromstates + [None]: |
paul@2 | 59 | # yep, we're now chatting |
paul@2 | 60 | newvalues['status'] = chatting_id |
paul@2 | 61 | |
paul@2 | 62 | |
paul@2 | 63 | def presetunread(db, cl, nodeid, newvalues): |
paul@2 | 64 | ''' Make sure the status is set on new issues |
paul@2 | 65 | ''' |
paul@2 | 66 | if newvalues.has_key('status') and newvalues['status']: |
paul@2 | 67 | return |
paul@2 | 68 | |
paul@2 | 69 | # get the unread state ID |
paul@2 | 70 | try: |
paul@2 | 71 | unread_id = db.status.lookup('unread') |
paul@2 | 72 | except KeyError: |
paul@2 | 73 | # no unread state, ignore all this stuff |
paul@2 | 74 | return |
paul@2 | 75 | |
paul@2 | 76 | # ok, do it |
paul@2 | 77 | newvalues['status'] = unread_id |
paul@2 | 78 | |
paul@2 | 79 | |
paul@2 | 80 | def init(db): |
paul@2 | 81 | # fire before changes are made |
paul@2 | 82 | db.issue.audit('set', chatty) |
paul@2 | 83 | db.issue.audit('create', presetunread) |
paul@2 | 84 | |
paul@2 | 85 | # vim: set filetype=python ts=4 sw=4 et si |