Ejemplo n.º 1
0
    def process_request(self, req):
        req.perm.assert_permission('REQUIREMENT_CREATE')
        template = 'newrequirement.cs';
        
        # No need to preview a tiny form like this
        if req.method == 'POST' and not req.args.has_key('preview'):
            self._do_create(req)
            
        requirement = Requirement(self.env)
        req.hdf['components'] = requirement.get_components() 
        req.hdf['trac.href.newrequirement'] = req.href.newrequirement()
        req.hdf['trac.href.auto_complete'] = req.href.newrequirement('ajax')

            
        req.hdf['title'] = 'New Requirement'

        # Provide FORM_TOKEN for Ajax POST request
        req.hdf['form_token'] = req.form_token
        

        add_stylesheet(req, 'hw/css/requirement.css')
        add_script(req, 'hw/javascript/prototype.js')
        add_script(req, 'hw/javascript/scriptaculous.js')
        return (template, None)
Ejemplo n.º 2
0
    def process_request(self, req):
        template = 'requirement.cs';
        db = self.env.get_db_cnx()

        if req.method == 'POST' and 'creator' in req.args and \
                not req.perm.has_permission('REQUIREMENT_MODIFY'):
            del req.args['creator']
        
        if req.method == 'POST': 
            self._do_modify(req, db)
        else:
            (component, fp, object) = self._get_requirement_parts(req)
            fp = Fp(self.env, name=fp)
            object = Object(self.env, name=object)
            requirement = Requirement(self.env, component, fp['id'], 
                                     object['id'], db)
            req.hdf['components'] = requirement.get_components() 
            req.hdf['requirement'] = requirement.values
            req.hdf['fp'] = fp['name']
            req.hdf['object'] = object['name']
            req.hdf['requirement.created'] = format_datetime(requirement.time_created)
            req.hdf['requirement.created_delta'] = pretty_timedelta(requirement.time_created)
            if requirement.time_changed != requirement.time_created:
                req.hdf['requirement'] = {
                    'lastmod': format_datetime(requirement.time_changed),
                    'lastmod_delta': pretty_timedelta(requirement.time_changed)
                }

            for field in RequirementSystem(self.env).get_requirement_fields():
                if field['type'] in ('radio', 'select'):
                    value = requirement.values.get(field['name'])
                    options = field['options']
                    if value and not value in options:
                        options.append(value)
                    field['options'] = options
                name = field['name']
                del field['name']
                if name in ('component', 'fp', 'object', 'status', 'creator', 'description'):
                    field['skip'] = True
                req.hdf['requirement.fields.' + name] = field

            req.hdf['requirement.description.formatted'] = wiki_to_html(
                requirement['description'], self.env, req, db)

            replyto = req.args.get('replyto')
            req.hdf['requirement'] = {
                'href': req.href.requirement('%s-%s-%s' % (requirement.component,
                                                           fp['name'],
                                                           object['name'])),
                'replyto': replyto
            }
            def quote_original(author, original, link):
                if not 'comment' in req.args: # i.e. the comment was not yet edited
                    req.hdf['requirement.comment'] = '\n'.join(
                        ['Replying to [%s %s]:' % (link, author)] +
                        ['> %s' % line for line in original.splitlines()] + [''])

            if replyto == 'description':
                quote_original(requirement['creator'], requirement['description'],
                               'requirement:%s-%s-%s' % (requirement.component,
                                                         fp['name'],
                                                         object['name']))

            replies = {}
            changes = []
            cnum = 0
            description_lastmod = description_author = None
            for change in self.grouped_changelog_entries(requirement, db):
                changes.append(change)
                # wikify comment
                comment = ''
                if 'comment' in change:
                    comment = change['comment']
                    change['comment'] = wiki_to_html(comment, self.env, req, db)

                cnum = change['cnum']
                # keep track of replies threading
                if 'replyto' in change:
                    replies.setdefault(change['replyto'], []).append(cnum)
                # eventually cite the replied to comment
                if replyto == str(cnum):
                    quote_original(change['author'], comment,
                                   'reqcomment:%s' % replyto)

                if 'description' in change['fields']:
                    change['fields']['description'] = ''
                    description_lastmod = change['date']
                    description_author = change['author']

            req.hdf['requirement'] = {
                'changes': changes,
                'replies': replies,
                'cnum': cnum + 1
                }

            if description_lastmod:
                req.hdf['requirement.description'] = {'lastmod': description_lastmod,
                                                      'author': description_author}

        req.hdf['title'] = 'Requirements'
        req.hdf['graph_path'] = req.href.requirement() + '/graph/'

        actions = RequirementSystem(self.env).get_available_actions(requirement, req.perm)
        for action in actions:
            req.hdf['requirement.actions.' + action] = '1'

        add_stylesheet(req, 'common/css/code.css')
        add_stylesheet(req, 'hw/css/requirement.css')
        return (template, None)