Changeset 4184

Show
Ignore:
Timestamp:
08/26/08 06:33:40 (3 months ago)
Author:
abbywinterscom
Message:

add support for workflow action side effects

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gridmodifyplugin/0.11/gridmod/web_ui.py

    r4126 r4184  
    88from trac.core import * 
    99from trac.perm import IPermissionRequestor         
    10 from trac.ticket import TicketSystem, Ticket 
     10from trac.ticket import TicketSystem 
    1111from trac.web.api import ITemplateStreamFilter 
    1212from trac.web.chrome import ITemplateProvider, add_script 
     
    1414from trac.util.datefmt import utc 
    1515from trac.ticket.notification import TicketNotifyEmail 
     16from trac.ticket.model import Ticket 
    1617from genshi.filters.transform import Transformer 
    1718from genshi.builder import tag 
     
    4748                id = req.args.get('ticket') 
    4849                ticket = Ticket(self.env, id) 
     50                action = 'leave' 
     51 
     52                # Save the action controllers we need to call side-effects for before 
     53                # we save the changes to the ticket. 
     54                controllers = list(self._get_action_controllers(req, ticket, action)) 
     55         
    4956                for field in TicketSystem(self.env).get_ticket_fields(): 
    5057                    val = req.args.get(field['name']) 
     
    5259                        ticket[field['name']] = val; 
    5360                ticket.save_changes(author=req.authname, comment='updated by gridmod plugin') 
    54                 tn = TicketNotifyEmail(self.env) 
    55                 tn.notify(ticket, newticket=False, modtime=now) 
    56                 # Add support for workflow actions 
     61 
     62                try: 
     63                    tn = TicketNotifyEmail(self.env) 
     64                    tn.notify(ticket, newticket=False, modtime=now) 
     65                except Exception, e: 
     66                    self.log.info("Failure sending notification on change to " 
     67                                  "ticket #%s: %s" % (ticket.id, e)) 
     68 
     69                # After saving the changes, apply the side-effects. 
     70                for controller in controllers: 
     71                    self.env.log.info('Side effect for %s' % 
     72                                       controller.__class__.__name__) 
     73                    controller.apply_action_side_effects(req, ticket, action) 
    5774            else: 
    5875                raise Exception('Permission denied') 
     
    92109        return stream 
    93110     
     111    def _get_action_controllers(self, req, ticket, action): 
     112        """Generator yielding the controllers handling the given `action`""" 
     113        for controller in TicketSystem(self.env).action_controllers: 
     114            actions = [a for w,a in 
     115                       controller.get_ticket_actions(req, ticket)] 
     116            if action in actions: 
     117                yield controller 
    94118 
    95119