Changeset 4446

Show
Ignore:
Timestamp:
10/12/08 15:54:58 (3 months ago)
Author:
coling
Message:

Allow client-event specific options to be saved. This changes a few things in the API.

Files:

Legend:

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

    r4438 r4446  
    3131    return "Send an email to a certain list of addresses" 
    3232 
    33   def instance_options(self): 
    34     yield {'name': 'XSLT', 'description': 'Formatting XSLT to convert the summary to an email'} 
     33  def options(self, client=None): 
     34    if client is None: 
     35      yield {'name': 'XSLT', 'description': 'Formatting XSLT to convert the summary to an email'} 
     36    else: 
     37      yield {'name': 'Email Addresses', 'description': 'Comma separated list of email addresses'} 
    3538 
    36   def client_options(self): 
    37     return [] 
    3839 
    3940  def init(self, instance, client): 
  • clientsplugin/0.11/clients/action.py

    r4438 r4446  
    1515    """ 
    1616 
     17  def options(client=None): 
     18    """The options for this action 
     19       If the client option is None then these options are defined as being per instance. 
     20    """ 
     21 
    1722  def perform(summary): 
    1823    """Perform the action. This must return an etree object 
  • clientsplugin/0.11/clients/admin.py

    r4444 r4446  
    77 
    88from clients.model import Client 
     9from clients.events import ClientEvent 
    910from trac.util.datefmt import utc, parse_date, get_date_format_hint, \ 
    1011                              get_datetime_format_hint 
     
    2122        if client: 
    2223            clnt = Client(self.env, client) 
     24            events = ClientEvent.select(self.env, client) 
    2325            if req.method == 'POST': 
    2426                if req.args.get('save'): 
     
    3234                    clnt.currency = req.args.get('currency') 
    3335                    clnt.update() 
     36 
     37                    for clev in events: 
     38                      for option in clev.summary_options: 
     39                        arg = 'summary-option-%s-%s' % (clev.md5, clev.summary_options[option]['md5']) 
     40                        clev.summary_options[option]['value'] = req.args.get(arg) 
     41                      for option in clev.action_options: 
     42                        arg = 'action-option-%s-%s' % (clev.md5, clev.action_options[option]['md5']) 
     43                        print arg 
     44                        print req.args.get(arg) 
     45                        clev.action_options[option]['value'] = req.args.get(arg) 
     46                      clev.update_options(client) 
     47 
    3448                    req.redirect(req.href.admin(cat, page)) 
    3549                elif req.args.get('cancel'): 
     
    3751 
    3852            add_script(req, 'common/js/wikitoolbar.js') 
    39             data = {'view': 'detail', 'client': clnt
     53            data = {'view': 'detail', 'client': clnt, 'events': events
    4054 
    4155        else: 
  • clientsplugin/0.11/clients/eventsadmin.py

    r4445 r4446  
    6565 
    6666            data = {'view': 'list', 
    67                     'events': ClientEvent.select(self.env), 
    68                     'summaries': ClientEventsSystem(self.env).get_summaries(), 
    69                     'actions': ClientEventsSystem(self.env).get_actions()} 
     67                    'events': ClientEvent.select(self.env)} 
    7068 
    7169        return 'admin_client_events.html', data 
  • clientsplugin/0.11/clients/events.py

    r4445 r4446  
    4242class ClientEvent(object): 
    4343 
    44     def __init__(self, env, name=None, db=None): 
     44    def __init__(self, env, name=None, client=None, db=None): 
    4545        self.env = env 
    4646        if name: 
     
    5656            if not row: 
    5757                raise TracError('Client Event %s does not exist.' % name) 
     58            self.md5 = md5.new(name).hexdigest() 
    5859            self.name = self._old_name = name 
    5960            self.summary = row[0] or '' 
    6061            self.action = row[1] or '' 
    6162            self.lastrun = row[2] or 0 
    62             self.loadoptions(db) 
     63            self.loadoptions(client, db) 
    6364        else: 
    6465            self.name = self._old_name = None 
     
    6869 
    6970 
    70     def loadoptions(self, db): 
     71    def loadoptions(self, client, db): 
    7172        assert self.exists, 'Cannot load options for a non-existent client event' 
    7273        system = ClientEventsSystem(self.env); 
     
    8081        cursor.execute("SELECT name, value " 
    8182                       "FROM client_event_summary_options " 
    82                        "WHERE client_event=%s AND client=''", (self._old_name,)) 
     83                       "WHERE client_event=%s AND client=%s", 
     84                       (self._old_name, client or '')) 
    8385        for name, value in cursor: 
    8486          options[name] = value 
    8587        self.summary_options = {} 
    86         for option in summary.instance_options(): 
     88        for option in summary.options(client): 
    8789          option['md5'] = md5.new(option['name']).hexdigest() 
    8890          if options.has_key(option['name']): 
     
    9496        cursor.execute("SELECT name, value " 
    9597                       "FROM client_event_action_options " 
    96                        "WHERE client_event=%s AND client=''", (self._old_name,)) 
     98                       "WHERE client_event=%s AND client=%s", 
     99                       (self._old_name, client or '')) 
    97100        for name, value in cursor: 
    98101          options[name] = value 
    99102        self.action_options = {} 
    100         for option in action.instance_options(): 
     103        for option in action.options(client): 
    101104          option['md5'] = md5.new(option['name']).hexdigest() 
    102105          if options.has_key(option['name']): 
     
    163166        cursor.execute("DELETE FROM " + table + " " 
    164167                       "WHERE client_event=%s AND client=%s", 
    165                        (self._old_name, client)) 
     168                       (self._old_name, client or '')) 
    166169        for option in options.values(): 
    167170          cursor.execute("INSERT INTO " + table + " (client_event, client, name, value) " 
    168171                         "VALUES (%s, %s, %s, %s)", 
    169                          (self._old_name, client, option['name'], option['value'])) 
    170  
    171         if handle_ta: 
    172             db.commit() 
    173  
    174  
    175     def update_options(self, db=None): 
     172                         (self._old_name, client or '', option['name'], option['value'])) 
     173 
     174        if handle_ta: 
     175            db.commit() 
     176 
     177 
     178    def update_options(self, client=None, db=None): 
    176179        assert self.exists, 'Cannot update non-existent client event' 
    177180        if not db: 
     
    181184            handle_ta = False 
    182185 
    183         self.update_client_options('', 'summary', self.summary_options, db) 
    184         self.update_client_options('', 'action', self.action_options, db) 
     186        self.update_client_options(client, 'summary', self.summary_options, db) 
     187        self.update_client_options(client, 'action', self.action_options, db) 
    185188 
    186189        if handle_ta: 
     
    207210            db.commit() 
    208211 
    209     def select(cls, env, db=None): 
     212    def select(cls, env, client=None, db=None): 
    210213        if not db: 
    211214            db = env.get_db_cnx() 
     
    215218                       "ORDER BY name") 
    216219        for name, summary, action, lastrun in cursor: 
    217             client = cls(env) 
    218             client.name = client._old_name = name 
    219             client.summary = summary or '' 
    220             client.action = action or '' 
    221             client.lastrun = lastrun or 0 
    222             client.loadoptions(db) 
    223             yield client 
     220            clev = cls(env) 
     221            clev.md5 = md5.new(name).hexdigest() 
     222            clev.name = clev._old_name = name 
     223            clev.summary = summary or '' 
     224            clev.action = action or '' 
     225            clev.lastrun = lastrun or 0 
     226            clev.loadoptions(client, db) 
     227            yield clev 
    224228    select = classmethod(select) 
  • clientsplugin/0.11/clients/summary_milestone.py

    r4436 r4446  
    3232    return "Provide a summary of tickets within all milestones that have completion dates set and give summaries of a milestone" 
    3333 
    34   def instance_options(self): 
    35     return [] 
    36  
    37   def client_options(self): 
     34  def options(self, client=None): 
    3835    return [] 
    3936 
  • clientsplugin/0.11/clients/summary.py

    r4436 r4446  
    1515    """ 
    1616 
    17   def instance_options(): 
    18     """Return a series of tupoles defining the option that can be set on this instance 
    19     """ 
    20  
    21   def client_options(): 
    22     """Return a series of tupoles defining the option that can be set on this client 
    23        for this specific instance. 
     17  def options(client=None): 
     18    """Return a series of tupoles defining the options 
    2419    """ 
    2520 
  • clientsplugin/0.11/clients/summary_ticketchanges.py

    r4436 r4446  
    3232    return "Provide a summary of ticket changes since the last run" 
    3333 
    34   def instance_options(self): 
    35     return [] 
    36  
    37   def client_options(self): 
     34  def options(self, client=None): 
    3835    return [] 
    3936 
  • clientsplugin/0.11/clients/templates/admin_clients.html

    r2708 r4446  
    4949          </div> 
    5050        </fieldset> 
     51        <py:for each="event in events"> 
     52          <py:for each="options in (event.summary_options, event.action_options)"> 
     53            <fieldset py:if="options"> 
     54              <py:with vars="field = options==event.summary_options and 'summary' or 'action'"> 
     55                <legend py:if="'summary'==field">Client Specific Summary Options for $event.name</legend> 
     56                <legend py:if="'action'==field">Client Specific Action Options for $event.name</legend> 
     57                <div py:for="option in options.values()" class="field"> 
     58                  <label>$option.name</label><br /> 
     59                  <!-- Todo: Support more modes other than intput type=text... --> 
     60                  <input type="text" name="${field}-option-${event.md5}-${option.md5}" size="60" value="$option.value"/> 
     61                  <p class="help">$option.description</p> 
     62                </div> 
     63              </py:with> 
     64            </fieldset> 
     65          </py:for> 
     66        </py:for> 
     67 
     68 
    5169        <fieldset> 
    5270          <legend>Change Notification Settings</legend>