Пример #1
0
    def _do_create_fp(self, req):
        """Adds a fp, its description, and hyponyms into the database.

        """
        if req.args.get('newfp') != '':
            fp = Fp(self.env)
            fp['name'] = req.args.get('newfp')
            fp['description'] = req.args.get('newfpdesc')
            fp.insert()
           
         
            hyps = req.args.get('newfphyps').split(',')
            for hyponym in hyps:
                if hyponym != "":
                    try:
                        # The only reason that inserting a hyponym
                        # would fail here is if one already existed in the db.
                        # By putting it in a try block and doing nothing 
                        # when we catch an error, we basically ignore any
                        # duplicate hyponyms the user enters. This is good
                        # because it makes sure all the non-duplicaties are
                        # added, quietly ignoring the duplicates (instead of
                        # erroring out on a duplicate and failing to add the
                        # rest of the hyponyms after the error).

                        newhyp = Hyponym(self.env)
                        newhyp['name'] = str(hyponym)
                        newhyp.values['fp'] = fp['id']
                        newhyp.insert()
                    except TracError:
                
                        pass
Пример #2
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))