Changeset 2703

Show
Ignore:
Timestamp:
10/25/07 06:30:38 (1 year ago)
Author:
coling
Message:

Remove the need for a hacked trac by using a request filter to manipulate the field type and options.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • clientsplugin/0.11/clients/api.py

    r2687 r2703  
    8787    def ticket_fields_need_upgrade(self): 
    8888        section = 'ticket-custom' 
    89         return not (self.config.get(section, 'client') and self.config.get(section, 'client_rate')) 
     89        return ('text' != self.config.get(section, 'client') \ 
     90                or 'text' != self.config.get(section, 'client_rate')) 
    9091     
    9192    def do_ticket_field_upgrade(self): 
    9293        section = 'ticket-custom' 
    9394         
    94         self.config.set(section,'client', 'select') 
    95         if not self.config.get(section, 'client.order'): 
    96             self.config.set(section, 'client.order', '1') 
    97         self.config.set(section,'client.options', 'custom:ClientsList') 
     95        self.config.set(section,'client', 'text') 
    9896        self.config.set(section,'client.label', 'Client') 
    99         self.config.set(section,'client.value', '0') 
    10097 
    10198        self.config.set(section,'client_rate', 'text') 
    102         if not self.config.get(section, 'client_rate.order'): 
    103             self.config.set(section, 'client_rate.order', '2') 
    10499        self.config.set(section,'client_rate.label', 'Client Charge Rate') 
    105         self.config.set(section,'client_rate.value', '') 
    106100 
    107101        self.config.save(); 
  • clientsplugin/0.11/clients/client.py

    r2685 r2703  
    11from trac.core import * 
    2 from trac.env import IEnvironmentSetupParticipant 
    3 from trac.ticket import ITicketCustomFieldValues 
     2from trac.web.api import IRequestFilter 
     3from trac.ticket.api import ITicketManipulator 
     4from trac.ticket.model import Ticket 
     5from trac.util.html import html, Markup 
    46 
    5 class ClientsList(Component): 
    6     implements(ITicketCustomFieldValues) 
     7from genshi.core import Markup 
     8from genshi.builder import tag 
     9from genshi.filters.transform import Transformer  
     10 
     11#from util import * 
     12from clients import model 
     13 
     14class ClientModule(Component): 
     15    """Allows for tickets to be assigned to particular clients.""" 
    716     
    8     def __init__(self): 
     17    implements(IRequestFilter) 
     18     
     19    # IRequestFilter methods 
     20    def pre_process_request(self, req, handler): 
     21        return handler 
     22         
     23    def post_process_request(self, req, template, data, content_type): 
     24        if req.path_info.startswith('/ticket/'): 
     25            for field in data['fields']: 
     26                if 'client' == field['name']: 
     27                    field['type'] = 'select' 
     28                    for client in model.Client.select(self.env): 
     29                        field['options'].append(client.name) 
     30                    break 
     31         
     32        return template, data, content_type 
     33         
     34    # ITicketManipulator methods 
     35    def prepare_ticket(self, req, ticket, fields, actions): 
    936        pass 
    10     def get_values(self): 
    11         db = self.env.get_db_cnx() 
    12         cursor = db.cursor() 
    13         cursor.execute("SELECT name FROM client") 
    14         rv = [] 
    15         for name in cursor: 
    16           rv.append((name,None)) 
    17         return rv 
     37         
     38    def validate_ticket(self, req, ticket): 
     39        # Todo validate client is valid 
     40        pass 
     41        #if req.args.get('action') == 'resolve': 
     42        #    links = TicketLinks(self.env, ticket) 
     43        #    for i in links.blocked_by: 
     44        #        if Ticket(self.env, i)['status'] != 'closed': 
     45        #            yield None, 'Ticket #%s is blocking this ticket'%i 
    1846