Пример #1
0
    def _do_create(self, req, db=None):
        if not req.args.get('component'):
            raise TracError('Requirements must contain a component.')
        
        if not req.args.get('fp'):
            raise TracError('Requirements must contain a functional primitive.')
        
        if not req.args.get('object'):
            raise TracError('Requirements must contain an object.')

        requirement = Requirement(self.env, db=db)
        requirement.populate(req.args)
        try:
            # if a known hyponym was used, get corresponding fp.
            temp_hyp = Hyponym(self.env, name=req.args.get('fp'), db=db)
            temp_fp = Fp(self.env, id=temp_hyp['fp'], db=db)
        except TracError:
            try:
                #or, if a known fp was used, get instance of Fp
                temp_fp = Fp(self.env, name=req.args.get('fp'), db=db)
            except TracError:
                #run check funtion for enabled adding fp
                #if unknown fp used, insert it into the database
                if(Fp(self.env).check_on_fly_fp() == "enabled"):
                    temp_fp = Fp(self.env, db=db)
                    temp_fp['name'] = req.args.get('fp')
                    temp_fp.insert(db=db)
                else:
                    raise TracError("On the fly creation of Fps disabled")
        requirement.values['fp'] = temp_fp['id']
        try:
            temp_object = Object(self.env, name=req.args.get('object'), db=db)
        except TracError:
        #run check for function enabling obj
            if(Object(self.env).check_on_fly_obj() == "enabled"): 
                temp_object = Object(self.env, db=db)
                temp_object['name'] = req.args.get('object')
                temp_object.insert(db=db)
            else:
                raise TracError("On the fly creation of objects disabled")
        requirement.values['object'] = temp_object['id']
        requirement.values['creator'] = get_reporter_id(req, 'creator')
        requirement.insert(db=db)

        # Notify
        try:
            rn = RequirementNotifyEmail(self.env)
            rn.notify(requirement, newrequirement=True)
        except Exception, e:
            self.log.exception("Failure sending notification on creation of "
                               "requirement <%s %s>: %s" % 
                               (temp_fp['name'], temp_object['name'], e))
Пример #2
0
    def _do_modify(self, req, db):
        self._do_arg_checks(req)
        component = req.args.get('component')
        fp = Fp(self.env, name=req.args.get('fp'))
        object = Object(self.env, name=req.args.get('object'))

        requirement = Requirement(self.env, component, fp['id'], object['id'], 
                                 db)

        status = requirement['status']
        requirement.populate(req.args)
        requirement['fp'] = fp['id']
        requirement['object'] = object['id']
        requirement['status'] = status

        now = int(time.time())
        cnum = req.args.get('cnum')
        replyto = req.args.get('replyto')
        internal_cnum = cnum
        if cnum and replyto:
            internal_cnum = '%s.%s' % (replyto, cnum)
    
        if (status != 'disabled' and req.args.get('status') != 'on') \
            or \
           (status == 'disabled' and req.args.get('status') == 'on'):

            req.perm.assert_permission('REQUIREMENT_DISENABLE')
            
            if req.args.get('status') == 'on':
                requirement['status'] = 'enabled'
            else:
                requirement['status'] = 'disabled'
            
        if requirement.save_changes(get_reporter_id(req, 'author'),
                                    req.args.get('comment'), when=now, db=db,
                                    cnum=internal_cnum):
            db.commit()

            # Notify
            try:
                rn = RequirementNotifyEmail(self.env)
                rn.notify(requirement, newrequirement=False)
            except Exception, e:
                self.log.exception("Failure sending notification on creation "
                                   "of requirement <%s %s>: %s" % 
                                   (fp['name'], object['name'], e))