Ejemplo n.º 1
0
 def _get_prefs_data(self, req, opts=None):
     """Returns the pref data, a dict of rule class titles whose values
     include lists of rule spec preference dicts each with these keys:
     
       id (based on unique key)
       label (of checkbox)
       enabled ('1' or '0')
       type ('none' or 'select'; TODO: 'text') 
       options (list of options if type is 'select')
       value (saved preference or default value)
     """
     if opts is None:
         opts = Options(self.env)
     data = {}
     for rule in self.rules:
         for key in opts:
             if not opts.has_pref(key):
                continue
             target_re = re.compile(r"(?P<target>[^.]+).*")
             target = target_re.match(key).groupdict()['target']
             trigger = rule.get_trigger(target, key, opts)
             if not trigger:
                 continue
             
             # this rule spec has a pref - so get it!
             pref = opts.get_pref(req, target, key)
             rule.update_pref(req, trigger, target, key, opts, pref)
             if rule.title not in data:
                 data[rule.title] = {'desc':rule.desc, 'prefs':[]}
             data[rule.title]['prefs'].append(pref)
     return data
Ejemplo n.º 2
0
 def _get_triggers(self, req):
     """Converts trac.ini config to dict of triggers with rule specs."""
     triggers = {}
     opts = Options(self.env)
     for key in opts:
         # extract the target field
         target_re = re.compile(r"(?P<target>[^.]+).*")
         target = target_re.match(key).groupdict()['target']
         
         # extract rule specifications from configs
         for rule in self.rules:
             trigger = rule.get_trigger(target, key, opts)
             if not trigger:
                 continue
             if not opts.is_enabled(req, key):
                 continue
             value,_ = opts.get_value_and_options(req, target, key)
             spec = {'rule_name':rule.name, 'trigger':trigger,
                     'target':target, 'value':value}
             rule.update_spec(req, key, opts, spec)
             if trigger not in triggers:
                 triggers[trigger] = [] # rule specs
             triggers[trigger].append(spec)
         
     return triggers
Ejemplo n.º 3
0
 def render_preference_panel(self, req, panel):
     opts = Options(self.env)
     if req.method == 'POST':
         opts.set_prefs(req)
     data = self._get_prefs_data(req, opts)
     return 'prefs_panel.html', {'data':data, 'saved':req.method == 'POST'}