Changeset 3995

Show
Ignore:
Timestamp:
07/09/08 13:14:03 (5 months ago)
Author:
k0s
Message:

policies are now read from the form; this enables adding new policies

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ticketsubmitpolicyplugin/0.11/ticketsubmitpolicy/templates/ticketsubmitpolicy.html

    r3994 r3995  
    1818    <div py:for="name in sorted(policies.keys())" class="plugin"> 
    1919      <h2>${name}</h2> 
     20 
     21      <input type="hidden" name="policy" value="${name}"/> 
    2022 
    2123      <div> 
     
    108110 
    109111    <div> 
    110       <input type="text"/> 
     112      <input type="text" name="new-policy"/> 
    111113      <input type="submit" name="add-policy" value="Add Policy"/> 
    112114    </div> 
  • ticketsubmitpolicyplugin/0.11/ticketsubmitpolicy/ticketsubmitpolicy.py

    r3994 r3995  
    349349        data to be passed to the template. 
    350350        """ 
    351         data = { 'policies': self.parse() } # data for template 
     351        data = {} # data for template 
    352352        data['fields'] = Ticket(self.env).fields # possible ticket fields 
    353353        data['comparitors'] = self.comparitors # implemented comparitors 
     
    361361 
    362362            # organize request args based on policy 
    363             args = dict([(key, {}) for key in data['policies']]) 
     363            policies = req.args.get('policy', []) 
     364            if isinstance(policies, basestring): 
     365                policies = [ policies ] 
     366            args = dict([(policy, {}) for policy in policies ]) 
    364367            for arg, value in req.args.items(): 
    365                 for policy in data['policies']
     368                for policy in policies
    366369                    token = '_%s' % policy 
    367370                    if arg.endswith(token): 
     
    369372                 
    370373            # get the conditions and policies from the request 
    371             old_policies = data['policies'] # XXX for debugging 
    372374            data['policies'] = {} 
    373375            for policy in args: 
     
    415417 
    416418 
     419            # added policy 
     420            new_policy = req.args.get('new-policy') 
     421            if new_policy: 
     422                data['policies'][new_policy] = dict(actions=[], condition=[]) 
     423 
    417424            # save the data if the user clicks apply 
    418425            if 'apply' in req.args: 
    419426                self.save(data['policies']) 
    420427                data['saved'] = True 
     428 
     429        if req.method == 'GET' or 'apply' in req.args: 
     430            data['policies'] = self.parse()  
    421431 
    422432        return ('ticketsubmitpolicy.html', data)