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
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")