Changeset 4099

Show
Ignore:
Timestamp:
07/31/08 15:52:50 (5 months ago)
Author:
datallah
Message:

Updates to support 0.11 (now featuring the ability to unset pending when attachments are uploaded)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pendingticketplugin/0.11/removependingplugin/removepending/remove_pending.py

    r2499 r4099  
    11# Plugin to remove Pending status when the reporter modifies a ticket 
    2 # Copyright 2007 Daniel A. Atallah <datallah@pidgin.im> 
     2# Copyright 2007-2008 Daniel A. Atallah <datallah@pidgin.im> 
    33 
     4from datetime import datetime 
    45from trac.core import * 
    5 from trac.ticket import ITicketChangeListener 
     6from trac.ticket import Ticket, ITicketChangeListener 
     7from trac.ticket.notification import TicketNotifyEmail 
     8from trac.ticket.web_ui import TicketModule 
     9from trac.attachment import IAttachmentChangeListener 
     10from trac.util.datefmt import to_timestamp, utc 
    611 
    712class RemovePendingPlugin(Component): 
    8         implements (ITicketChangeListener
     13        implements (ITicketChangeListener, IAttachmentChangeListener
    914 
    1015        def ticket_created(self, ticket): 
     
    1217 
    1318        def ticket_changed(self, ticket, comment, author, old_values): 
    14                 if (author == ticket['reporter'] and ticket['pending'] == '1' and not old_values.has_key('pending')): 
    15                         db, handle_ta = ticket._get_db_for_write(None) 
    16                         cursor = db.cursor() 
     19                if (not old_values.has_key('pending')): 
     20                        if (author == ticket['reporter'] and ticket['pending'] == '1'): 
     21                                self.env.log.info('Removing Pending status for ticket %s due to comment' 
     22                                                  % (ticket.id)) 
    1723 
    18                         cursor.execute("UPDATE ticket_custom SET value = %s " \ 
    19                                 " WHERE ticket = %s AND name = %s ", 
    20                                 ('0', ticket.id, 'pending')) 
     24                                db, handle_ta = ticket._get_db_for_write(None) 
     25                                cursor = db.cursor() 
    2126 
    22                         #Add the ticket change so that it will appear 
    23                         #correctly in the history and notifications 
    24                         cursor.execute("INSERT INTO ticket_change " 
    25                                 "(ticket,time,author,field,oldvalue,newvalue) " 
    26                                 "VALUES (%s, %s, %s, %s, %s, %s)", 
    27                         (ticket.id, ticket.time_changed, author, 'pending', '1', '0')) 
     27                                cursor.execute("UPDATE ticket_custom SET value = %s " \ 
     28                                        " WHERE ticket = %s AND name = %s ", 
     29                                        ('0', ticket.id, 'pending')) 
    2830 
    29                         db.commit(); 
     31                                #Add the ticket change so that it will appear 
     32                                #correctly in the history and notifications 
     33                                cursor.execute("INSERT INTO ticket_change " 
     34                                        "(ticket,time,author,field,oldvalue,newvalue) " 
     35                                        "VALUES (%s, %s, %s, %s, %s, %s)", 
     36                                (ticket.id, to_timestamp(time_changed), author, 'pending', '1', '0')) 
     37 
     38                                db.commit(); 
    3039 
    3140        def ticket_deleted(self, ticket): 
    3241                pass 
    3342 
     43        def attachment_added(self, attachment): 
     44                # Check whether we're dealing with a ticket resource 
     45                resource = attachment.resource 
     46                while resource: 
     47                        if resource.realm == 'ticket': 
     48                                break 
     49                        resource = resource.parent 
     50 
     51                if (resource and resource.realm == 'ticket' and resource.id is not None): 
     52                        db = attachment.env.get_db_cnx(); 
     53                        ticket = Ticket(attachment.env, resource.id, db) 
     54                        if (attachment.author == ticket['reporter'] and ticket['pending'] == '1'): 
     55                                self.env.log.info('Removing Pending status for ticket %s due to attachment' 
     56                                                  % (ticket.id)) 
     57 
     58                                comment = 'Attachment (%s) added by ticket reporter.' % (attachment.filename) 
     59                                ticket['pending'] = '0' 
     60 
     61                                # determine sequence number... 
     62                                cnum = 0 
     63                                tm = TicketModule(self.env) 
     64                                for change in tm.grouped_changelog_entries(ticket, db): 
     65                                        if change['permanent']: 
     66                                                cnum += 1 
     67 
     68                                #We can't just use attachment.date as it screws up event sequencing 
     69                                now = datetime.now(utc) 
     70 
     71                                ticket.save_changes(attachment.author, comment, now, db, cnum + 1) 
     72                                db.commit() 
     73 
     74                                #trigger notification since we've changed the ticket 
     75                                tn = TicketNotifyEmail(self.env) 
     76                                tn.notify(ticket, newticket=False, modtime=now) 
     77 
     78        def attachment_deleted(self, attachment): 
     79                pass 
     80 
  • pendingticketplugin/0.11/removependingplugin/setup.py

    r2500 r4099  
    66setup( 
    77    name = 'RemovePendingStatusPlugin', 
    8     version = '0.0.2', 
     8    version = '0.0.3', 
    99    packages = ['removepending'], 
    1010