def render_admin_panel(self, req, cat, page, path_info): req.perm.assert_permission('TCF_ADMIN') data = {} if req.method == 'POST': if 'save' in req.args: tcf_define_json = req.args.get("tcf_define", "").strip() try: tcf_define = simplejson.loads(tcf_define_json) except: raise TracError(u"Format error, which should be JSON. Please back to last page and check the configuration.") TracTicketChainedFields_List.insert(self.env, tcf_define_json) req.redirect(req.abs_href.admin(cat, page)) else: data["tcf_define"] = TracTicketChainedFields_List.get_tcf_define(self.env) return 'tcf_admin.html', data
def render_admin_panel(self, req, cat, page, path_info): req.perm.assert_permission('TCF_ADMIN') data = {} if req.method == 'POST': if 'save' in req.args: tcf_define_json = req.args.get("tcf_define", "").strip() try: tcf_define = simplejson.loads(tcf_define_json) except: raise TracError( u"Format error, which should be JSON. Please back to last page and check the configuration." ) TracTicketChainedFields_List.insert(self.env, tcf_define_json) req.redirect(req.abs_href.admin(cat, page)) else: data["tcf_define"] = TracTicketChainedFields_List.get_tcf_define( self.env) return 'tcf_admin.html', data
def process_request(self, req): hide_empty_fields = self.config.getbool("tcf", "hide_empty_fields", False) chained_fields = self.config.getlist("tcf", "chained_fields", []) if req.path_info.startswith('/tcf/query_tcf_define'): # handle XMLHTTPRequest result = {} result["status"] = "1" result["hide_empty_fields"] = hide_empty_fields result["chained_fields"] = chained_fields tcf_define = TracTicketChainedFields_List.get_tcf_define(self.env) try: result["tcf_define"] = simplejson.loads(tcf_define) except: pass if req.args.has_key("warning"): result["warning"] = "1" jsonstr = simplejson.dumps(result) self._sendResponse(req, jsonstr) elif req.path_info.startswith('/tcf/query_field_change'): result = {} result["status"] = "1" result["hide_empty_fields"] = hide_empty_fields trigger = req.args.get("trigger", "").lstrip("field-") trigger_value = req.args.get("field-" + trigger, "") if not trigger: result["status"] = "0" tcf_define = TracTicketChainedFields_List.get_tcf_define(self.env) try: tcf_define_target = simplejson.loads(tcf_define) except: pass def locate_trigger_values(root): if trigger in root: return root[trigger].get(trigger_value) for field, field_values in root.items(): field_value = req.args.get("field-" + field, "") if not field_value: # skip field not specified continue trigger_values = locate_trigger_values(field_values.get(field_value, {})) if trigger_values: # return when found return trigger_values trigger_values = locate_trigger_values(tcf_define_target) target_options = [] targets = [] if trigger_values: for k, v in trigger_values.items(): target_field = k target_options = [target_option for target_option in v.keys() if target_option] target_options.sort(cmp=lambda x,y: cmp(x.lower(), y.lower())) targets.append({ "target_field": target_field, "target_options": target_options, }) result["targets"] = targets if req.args.has_key("warning"): result["warning"] = "1" jsonstr = simplejson.dumps(result) self._sendResponse(req, jsonstr)
def process_request(self, req): hide_empty_fields = self.config.getbool("tcf", "hide_empty_fields", False) chained_fields = self.config.getlist("tcf", "chained_fields", []) if req.path_info.startswith('/tcf/query_tcf_define'): # handle XMLHTTPRequest result = {} result["status"] = "1" result["hide_empty_fields"] = hide_empty_fields result["chained_fields"] = chained_fields tcf_define = TracTicketChainedFields_List.get_tcf_define(self.env) try: result["tcf_define"] = simplejson.loads(tcf_define) except: pass if req.args.has_key("warning"): result["warning"] = "1" jsonstr = simplejson.dumps(result) self._sendResponse(req, jsonstr) elif req.path_info.startswith('/tcf/query_field_change'): result = {} result["status"] = "1" result["hide_empty_fields"] = hide_empty_fields trigger = req.args.get("trigger", "").lstrip("field-") trigger_value = req.args.get("field-" + trigger, "") if not trigger: result["status"] = "0" tcf_define = TracTicketChainedFields_List.get_tcf_define(self.env) try: tcf_define_target = simplejson.loads(tcf_define) except: pass def locate_trigger_values(root): if trigger in root: return root[trigger].get(trigger_value) for field, field_values in root.items(): field_value = req.args.get("field-" + field, "") if not field_value: # skip field not specified continue trigger_values = locate_trigger_values( field_values.get(field_value, {})) if trigger_values: # return when found return trigger_values trigger_values = locate_trigger_values(tcf_define_target) target_options = [] targets = [] if trigger_values: for k, v in trigger_values.items(): target_field = k target_options = [ target_option for target_option in v.keys() if target_option ] target_options.sort( cmp=lambda x, y: cmp(x.lower(), y.lower())) targets.append({ "target_field": target_field, "target_options": target_options, }) result["targets"] = targets if req.args.has_key("warning"): result["warning"] = "1" jsonstr = simplejson.dumps(result) self._sendResponse(req, jsonstr)