def _show_prototype(self, req, path_info, action): """Handler for creating a new prototype.""" data = {"name": path_info, "action": action} proto = None if req.method == "POST": proto = Prototype(self.env, "") for i in itertools.count(): a = req.args.get("step-%s" % i) if a is not None: proto.append((a, req.args["args-%s" % a])) else: break if "movedown" in req.args: i = int(req.args["movedown"]) x = proto.pop(i) proto.insert(i + 1, x) elif "moveup" in req.args: i = int(req.args["moveup"]) x = proto.pop(i) proto.insert(i - 1, x) elif "remove" in req.args: i = int(req.args["remove"]) del proto[i] elif "add" in req.args: proto.append((req.args["type"], "")) elif "save" in req.args: proto.tag = (action == "new" and req.args["name"] or data["name"]).strip() if not proto.tag or proto.tag == "new": raise TracError('Invalid prototype name "%s"', proto.tag) proto.save() req.redirect(req.href.admin("tracforge/prototypes", proto.tag)) elif "cancel" in req.args: req.redirect(req.href.admin("tracforge/prototypes")) elif "delete" in req.args: proto.tag = data["name"] proto.delete() req.redirect(req.href.admin("tracforge/prototypes")) # Try to figure out the name if action == "new": proto.tag = req.args["name"] else: proto.tag = "(modified) %s" % data["name"] # steps = {} # for p in self.setup_participants: # for a in p.get_setup_actions(): # steps[a] = { # 'provider': p, # 'description': p.get_setup_action_description(a), # } data["steps"] = TracForgeAdminSystem(self.env).get_project_setup_participants() if action == "new": # For a new one, use the specified defaults if proto is None: proto = Prototype.default(self.env) # XXX: This should really read from trac.ini somehow elif action == "edit": if proto is None: proto = Prototype(self.env, data["name"]) if not proto.exists: raise TracError("Unknown prototype %s" % proto.tag) else: raise TracError("Invalid action %s" % action) data["proto"] = proto add_stylesheet(req, "tracforge/css/prototypes_new.css") # add_script(req, 'tracforge/js/interface/iutil.js') # add_script(req, 'tracforge/js/jquery.animatedswap.js') return "admin_tracforge_prototype.html", data
def _show_prototype(self, req, path_info, action): """Handler for creating a new prototype.""" data = { 'name': path_info, 'action': action, } proto = None if req.method == 'POST': proto = Prototype(self.env, '') for i in itertools.count(): a = req.args.get('step-%s'%i) if a is not None: proto.append((a, req.args['args-%s'%a])) else: break if 'movedown' in req.args: i = int(req.args['movedown']) x = proto.pop(i) proto.insert(i+1, x) elif 'moveup' in req.args: i = int(req.args['moveup']) x = proto.pop(i) proto.insert(i-1, x) elif 'remove' in req.args: i = int(req.args['remove']) del proto[i] elif 'add' in req.args: proto.append((req.args['type'], '')) elif 'save' in req.args: proto.tag = (action == 'new' and req.args['name'] or data['name']).strip() if not proto.tag or proto.tag == 'new': raise TracError('Invalid prototype name "%s"', proto.tag) proto.save() req.redirect(req.href.admin('tracforge/prototypes', proto.tag)) elif 'cancel' in req.args: req.redirect(req.href.admin('tracforge/prototypes')) elif 'delete' in req.args: proto.tag = data['name'] proto.delete() req.redirect(req.href.admin('tracforge/prototypes')) # Try to figure out the name if action == 'new': proto.tag = req.args['name'] else: proto.tag = '(modified) %s'%data['name'] #steps = {} #for p in self.setup_participants: # for a in p.get_setup_actions(): # steps[a] = { # 'provider': p, # 'description': p.get_setup_action_description(a), # } data['steps'] = TracForgeAdminSystem(self.env).get_project_setup_participants() if action == 'new': # For a new one, use the specified defaults if proto is None: proto = Prototype.default(self.env) # XXX: This should really read from trac.ini somehow elif action == 'edit': if proto is None: proto = Prototype(self.env, data['name']) if not proto.exists: raise TracError('Unknown prototype %s'%proto.tag) else: raise TracError('Invalid action %s'%action) data['proto'] = proto add_stylesheet(req, 'tracforge/css/prototypes_new.css') #add_script(req, 'tracforge/js/interface/iutil.js') #add_script(req, 'tracforge/js/jquery.animatedswap.js') return 'admin_tracforge_prototype.html', data