Commits

Peter Suter committed fcbb725

Move batch modification template data preparation to BatchModule

Comments (0)

Files changed (2)

trac/ticket/batch.py

 import re
 from datetime import datetime
 
+from genshi.builder import tag
+
 from trac.core import *
 from trac.ticket import TicketSystem, Ticket
 from trac.ticket.notification import BatchTicketNotifyEmail
 from trac.util.text import exception_to_unicode, to_unicode
 from trac.util.translation import tag_
 from trac.web import IRequestHandler
-from trac.web.chrome import add_warning
-
+from trac.web.chrome import add_warning, add_script_data
 
 class BatchModifyModule(Component):
     """Ticket batch modification module.
     
     This component allows multiple tickets to be modified in one request from
     the custom query page. For users with the TICKET_BATCH_MODIFY permission
-    it will add a batch modify section underneath custom query results. Users
-    can choose which tickets and fields they wish to modify.
+    it will add a [TracBatchModify batch modify] section underneath custom
+    query results. Users can choose which tickets and fields they wish to
+    modify.
     """
     
     implements(IRequestHandler)
         else:
             return selected_tickets.split(',')
 
+    def add_template_data(self, req, data, tickets):
+        data['batch_modify'] = True
+        data['query_href'] = req.session['query_href'] or req.href.query()
+        data['action_controls'] = self._get_action_controls(req, tickets)
+        add_script_data(req, batch_modify=True)
+
+    def _get_action_controls(self, req, tickets):
+        action_controls = []
+        ts = TicketSystem(self.env)        
+        ticket_actions = []
+        for t in tickets:
+            ticket = Ticket(self.env, t['id'])
+            ticket_actions.extend(ts.get_available_actions(req, ticket))
+        sorted_actions = sorted(set(ticket_actions))
+        for action in sorted_actions:
+            first_label = None
+            hints = []
+            widgets = []
+            for controller in self._get_action_controllers(req, ticket,
+                                                           action):
+                label, widget, hint = controller.render_ticket_action_control(
+                    req, ticket, action)
+                if not first_label:
+                    first_label = label
+                widgets.append(widget)
+                hints.append(hint)
+            action_controls.append((action, first_label, tag(widgets), hints))
+        return action_controls
+
     def _get_action_controllers(self, req, ticket, action):
         """Generator yielding the controllers handling the given `action`"""
         for controller in TicketSystem(self.env).action_controllers:

trac/ticket/query.py

         from trac.ticket.batch import BatchModifyModule
         if 'TICKET_BATCH_MODIFY' in req.perm and \
                 self.env.is_component_enabled(BatchModifyModule):
-            self._add_batch_modify_data(req, data, tickets)
+            self.env[BatchModifyModule].add_template_data(req, data, tickets)
             
         data.setdefault('report', None)
         data.setdefault('description', None)
             except QuerySyntaxError, e:
                 return tag.em(_('[Error: %(error)s]', error=unicode(e)), 
                               class_='error')
-    
-    def _add_batch_modify_data(self, req, data, tickets):
-        data['batch_modify'] = True
-        data['query_href'] = req.session['query_href'] or req.href.query()
-        data['action_controls'] = self._get_batch_modify_action_controls(
-            req, tickets)
-        add_script_data(req, {'batch_modify': True})
 
-    def _get_batch_modify_action_controls(self, req, tickets):
-        action_controls = []
-        ts = TicketSystem(self.env)        
-        ticket_actions = []
-        for t in tickets:
-            ticket = Ticket(self.env, t['id'])
-            ticket_actions.extend(ts.get_available_actions(req, ticket))
-        sorted_actions = sorted(set(ticket_actions))
-        for action in sorted_actions:
-            first_label = None
-            hints = []
-            widgets = []
-            for controller in self._get_action_controllers(req, ticket,
-                                                           action):
-                label, widget, hint = controller.render_ticket_action_control(
-                    req, ticket, action)
-                if not first_label:
-                    first_label = label
-                widgets.append(widget)
-                hints.append(hint)
-            action_controls.append((action, first_label, tag(widgets), hints))
-        return action_controls
-        
-    def _get_action_controllers(self, req, ticket, action):
-        """Generator yielding the controllers handling the given `action`"""
-        for controller in TicketSystem(self.env).action_controllers:
-            actions = [a for w, a in
-                       controller.get_ticket_actions(req, ticket) or []]
-            if action in actions:
-                yield controller
 
 class TicketQueryMacro(WikiMacroBase):
     _domain = 'messages'