示例#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))
示例#3
0
    def _do_modify_fp(self, req):
        """Modifies an object, its description, and or its status and updates it         database from the data passed from the web user interface.

        """

        fp_dict_str = base64.b64decode(req.args['fp_state_dict'])
        fp_list = pickle.loads(fp_dict_str)

        changed_desc = [name[12:] for name in req.args.keys() \
                                  if name[:12] == "change_desc_"]
        changed_hyp_names = [name[11:] for name in req.args.keys() \
                                       if name[:11] == "change_hyp_"]
        changed_fp_names = [name[10:] for name in req.args.keys() \
                                      if name[:10] == "change_fp_"]
        checked_fp_names = [name[10:] for name in req.args.keys() \
                                      if name[:10] =="status_fp_"]
        checked_hyp_names = [name[11:] for name in req.args.keys() \
                                       if name[:11] =="status_hyp_"]
        new_hyp_fps = [name[8:] for name in req.args.keys() \
                                if name[:8] =="new_hyp_"]
        swap_hyp_fps = [name[5:] for name in req.args.keys() \
                                 if name[:5]=="swap_"]

        #Updating Fps that were modified
        for item in fp_list:
            fp_name, status = item['fp']
            tmp = Fp(self.env, name = fp_name)
            changed = False

            if fp_name in changed_desc:
                tmp_desc = req.args['change_desc_' + fp_name] 
                if tmp_desc != item['description']:
                    tmp['description'] = \
                    req.args['change_desc_' + fp_name]
                    changed = True
        
            if fp_name in changed_fp_names \
            and req.args['change_fp_' + fp_name]!= "":
                tmp['name'] = req.args['change_fp_' + fp_name]
                changed = True

            if fp_name in checked_fp_names:
                #Checkbox was was checked
                if status != "enabled":
                    tmp['status'] = "enabled"
                    changed = True
            else:
                #Checkbox wasn't checked
                if status == "enabled":
                    tmp['status'] = "disabled"
                    changed = True

            if changed:
                tmp.save_changes(req.authname, "Fp modified")

        #Updating hyponyms that were modified
        for item in fp_list:
            for hyp_name, status in item['hyponyms']:
                tmp = Hyponym(self.env, name = hyp_name)
                changed = False

                if hyp_name in checked_hyp_names:
                    #Checkbox was was checked
                    if status != "enabled":
                        tmp['status'] = "enabled"
                        changed = True
                else:
                    #Checkbox wasn't checked
                    if status == "enabled":
                        tmp['status'] = "disabled"
                        changed = True

                if req.args['change_hyp_' + hyp_name] != "":
                    if hyp_name in changed_hyp_names: 
                        tmp['name'] = req.args['change_hyp_' + hyp_name]
                        changed = True 
                if changed:
                    tmp.save_changes(req.authname, "Hyponym Modified")

        for fp_name in new_hyp_fps: 
            hyps = req.args.get('new_hyp_' + fp_name).split(',')
            for hyponym in hyps:
                if hyponym != "":
                    try:
                        # If the point of this try statement confuses you,
                        # scroll down to see the next fatty comment block,
                        # or search this file for the word 'duplicate'
                        newhyp = Hyponym(self.env)
                        newhyp['name'] = str(hyponym)
                        newhyp.values['fp'] = Fp(self.env, name=fp_name)['id']
                        newhyp.insert()
                    except TracError:
                        pass

        for item in swap_hyp_fps:
            if req.args['swap_' + item] != 'hyponym':
                temp = Hyponym(self.env, name=req.args['swap_' + item])
                temp.swap_with_fp(req.authname, "Swapped Fp with Hyponym")