コード例 #1
0
    def _show_prototype(self, req, path_info, action):
        """Handler for creating a new prototype."""
        add_stylesheet(req, 'tracforge/css/prototypes_new.css')
        add_script(req, 'tracforge/js/interface/iutil.js')
        add_script(req, 'tracforge/js/jquery.animatedswap.js')
        req.hdf['tracforge.prototypes.name'] = path_info.strip('/')

        if req.method == 'POST':
            if req.args.get(
                    'save'
            ):  # Save either a new prototype or a changed existing ones
                name = req.args.get('name')
                if action == 'edit':
                    name = path_info.strip('/')
                if not name:
                    raise TracError(
                        'You must specify a name for the prototype')
                if name in ('new', 'configset'):
                    raise TracError('"new" and "configset" are reserved names')

                data = req.args.get('data')
                if data is None:
                    raise TracError(
                        "Warning: Peguins on fire. You might have JavaScript off, don't do that"
                    )
                data = data[4:]  # Strip off the 'data' literal at the start
                if not data:
                    raise TracError(
                        "You must have at least one step in a prototype")

                proto = Prototype(self.env, name)
                if action == 'new' and proto.exists:
                    raise TracError("Prototype %s already exists" % name)
                del proto[:]
                for x in data.split('|'):
                    proto.append(x.split(',', 1))
                proto.save()
            elif req.args.get('cancel'):
                pass  # This should just redirect back
            elif req.args.get(
                    'delete'
            ) and action == 'edit':  # Show the confirmation screen
                return 'admin_tracforge_prototypes_delete.cs', None
            elif req.args.get(
                    'reallydelete'
            ) and action == 'edit':  # Actually delete this prototype
                name = path_info.strip('/')
                proto = Prototype(self.env, name)
                if not proto.exists:
                    raise TracError('Prototype %s does not exist' % name)
                proto.delete()
            req.redirect(req.href.admin(req.cat, req.page))

        #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),
        #        }
        steps = TracForgeAdminSystem(self.env).get_project_setup_participants()

        initial_steps = []
        if action == 'new':  # For a new one, use the specified defaults
            initial_steps = Prototype.default(
                self.env)  # XXX: This should really read from trac.ini somehow
        elif action == 'edit':
            proto = Prototype(self.env, path_info.strip('/'))
            if not proto.exists:
                raise TracError('Unknown prototype %s' % proto.tag)
            initial_steps = proto
        else:
            raise TracError('Invalid action %s' % action)

        req.hdf['tracforge.prototypes.action'] = action
        req.hdf['tracforge.prototypes.steps'] = steps
        req.hdf['tracforge.prototypes.initialsteps'] = initial_steps
        req.hdf['tracforge.prototypes.liststeps'] = [
            k for k in steps.iterkeys() if k not in initial_steps
        ]

        return 'admin_tracforge_prototypes_show.cs', None
コード例 #2
0
    def _show_prototype(self, req, path_info, action):
        """Handler for creating a new prototype."""
        add_stylesheet(req, 'tracforge/css/prototypes_new.css')
        add_script(req, 'tracforge/js/interface/iutil.js')
        add_script(req, 'tracforge/js/jquery.animatedswap.js')
        req.hdf['tracforge.prototypes.name'] = path_info.strip('/')
        
        if req.method == 'POST':
            if req.args.get('save'): # Save either a new prototype or a changed existing ones
                name = req.args.get('name')
                if action == 'edit':
                    name = path_info.strip('/')
                if not name:
                    raise TracError('You must specify a name for the prototype')
                if name in ('new', 'configset'):
                    raise TracError('"new" and "configset" are reserved names')
            
                data = req.args.get('data')
                if data is None:
                    raise TracError("Warning: Peguins on fire. You might have JavaScript off, don't do that")
                data = data[4:] # Strip off the 'data' literal at the start
                if not data:
                    raise TracError("You must have at least one step in a prototype")
                
                proto = Prototype(self.env, name)
                if action == 'new' and proto.exists:
                    raise TracError("Prototype %s already exists"%name)
                del proto[:]
                for x in data.split('|'):
                    proto.append(x.split(',',1))
                proto.save()
            elif req.args.get('cancel'): 
                pass # This should just redirect back
            elif req.args.get('delete') and action == 'edit': # Show the confirmation screen
                return 'admin_tracforge_prototypes_delete.cs', None
            elif req.args.get('reallydelete') and action == 'edit': # Actually delete this prototype
                name = path_info.strip('/')
                proto = Prototype(self.env, name)
                if not proto.exists:
                    raise TracError('Prototype %s does not exist'%name)
                proto.delete()
            req.redirect(req.href.admin(req.cat, req.page))

        #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),
        #        }
        steps = TracForgeAdminSystem(self.env).get_project_setup_participants()
        
        initial_steps = []        
        if action == 'new': # For a new one, use the specified defaults 
            initial_steps = Prototype.default(self.env) # XXX: This should really read from trac.ini somehow
        elif action == 'edit': 
            proto = Prototype(self.env, path_info.strip('/'))
            if not proto.exists:
                raise TracError('Unknown prototype %s'%proto.tag)
            initial_steps = proto
        else:
            raise TracError('Invalid action %s'%action)

        req.hdf['tracforge.prototypes.action'] = action
        req.hdf['tracforge.prototypes.steps'] = steps
        req.hdf['tracforge.prototypes.initialsteps'] = initial_steps
        req.hdf['tracforge.prototypes.liststeps'] = [k for k in steps.iterkeys() if k not in initial_steps]
        
        return 'admin_tracforge_prototypes_show.cs', None