Changeset 3994

Show
Ignore:
Timestamp:
07/09/08 12:36:22 (6 months ago)
Author:
k0s
Message:

saving is now handled; all that is needed for minimal functionality is the ability to add new policies

Files:

Legend:

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

    r3993 r3994  
    1010  </head> 
    1111  <body> 
     12 
     13    <div py:if="not saved"> 
     14      The policy is not saved.  Please click 'Apply Changes' to save 
     15    </div> 
    1216 
    1317    <form method="post"> 
     
    9296            </py:for>                  
    9397          </select> 
     98 
     99          <!-- dummy submit button for action adding --> 
     100          <input type="submit" name="actionbutton_${name}" value="+"/> 
    94101        </py:if> 
    95102 
  • ticketsubmitpolicyplugin/0.11/ticketsubmitpolicy/ticketsubmitpolicy.py

    r3993 r3994  
    5151            retval[policy.name()] = policy 
    5252        return retval 
     53 
     54    def save(self, policies): 
     55 
     56        # shorthand 
     57        section = 'ticket-submit-policy' 
     58        config = self.env.config 
     59 
     60        # remove the old section 
     61        for key, value in config.options(section): 
     62            config.remove(section, key) 
     63 
     64        # create new section from policy dictionary 
     65        for policy in policies: 
     66            condition = policies[policy]['condition'] 
     67            if condition: 
     68                value = ' && '.join(['%s %s %s' % (i['field'], i['comparitor'], i['value']) for i in condition]) 
     69                config.set(section,  
     70                           '%s.condition' % policy, 
     71                           value) 
     72            for action in policies[policy]['actions']: 
     73                config.set(section, 
     74                           '%s.%s' % (policy, action['name']), 
     75                           ', '.join(action['args'])) 
     76 
     77        # save the policy 
     78        config.save() 
    5379 
    5480    def parse(self): 
     
    327353        data['comparitors'] = self.comparitors # implemented comparitors 
    328354        data['self_actions'] = self.policies # available policies 
     355        data['saved'] = True 
    329356 
    330357        if req.method == 'POST': 
     358 
     359            # mark the page as unsaved 
     360            data['saved'] = False 
    331361 
    332362            # organize request args based on policy 
     
    339369                 
    340370            # get the conditions and policies from the request 
    341             old_policies = data['policies'] 
     371            old_policies = data['policies'] # XXX for debugging 
    342372            data['policies'] = {} 
    343373            for policy in args: 
     
    360390                    if field.startswith(token): 
    361391                        name = field.split(token, 1)[1] 
    362                         action_args = [ i.strip() for i in value.split(',') ] 
    363                         data['policies'][policy]['actions'].append(dict(name=name, args=action_args)) 
     392                        if args[policy].get('rm_action_%s' % name, False): 
     393                            continue 
     394 
     395                        if isinstance(value, basestring):       
     396                            value = [ value ] 
     397                        data['policies'][policy]['actions'].append(dict(name=name, args=value)) 
    364398                         
    365399                # added action 
     
    383417            # save the data if the user clicks apply 
    384418            if 'apply' in req.args: 
    385                 pass 
     419                self.save(data['policies']) 
     420                data['saved'] = True 
    386421 
    387422        return ('ticketsubmitpolicy.html', data)