def _delete_evaluation(self, evaltype, id, id2, uid=None, username=None): if not h.auth.is_logged_in(): abort(401) id2 = request.params.get('id2', id2) uid = request.params.get('uid', uid) username = request.params.get('username', username) evaluation = self._get_evaluation(id, id2, uid, username, autoCreate=False) if not evaluation: abort(404) current_uid = h.get_user(request.environ['REMOTE_USER']).ID if evaluation.uid != current_uid or not h.auth.is_admin(): abort(401) setattr(evaluation, evaltype, -1) # Delete evaluation if this eliminates both settings, new db schema # will eliminate this need if evaluation.generality == -1 and evaluation.relatedness == -1: h.delete_obj(evaluation) else: # save change in evaluation Session.flush() Session.commit() response.status_int = 200 return "OK"
def _delete_evaluation(self, evaltype, id, id2, uid=None, username=None): id2 = request.params.get('id2', id2) uid = request.params.get('uid', uid) username = request.params.get('username', username) # look for a specific user's feedback evaluation = self._get_evaluation(evaltype, id, id2, uid, username, autoCreate=False) # if that feedback does not exist, unleash the nuclear option and delete # ALL evaluation facts for this relation, wiping it from the database. if h.auth.is_admin() and not evaluation: eval_q = Session.query(evaltype) eval_q = eval_q.filter_by(ante_id=id, cons_id=id2) evals = eval_q.all() # wipe them out. all of them. for evaluation in evals: h.delete_obj(evaluation) # return ok, with how many were deleted response.status_int = 200 return "OK %d" % len(evals) elif not evaluation: abort(404) # simply return an error (not evaluated), if not admin current_uid = h.get_user(request.environ['REMOTE_USER']).ID if evaluation.uid != current_uid and not h.auth.is_admin(): abort(401) h.delete_obj(evaluation) response.status_int = 200 return "OK"
def delete(self, id=None): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) journal = h.fetch_obj(Journal, id) h.delete_obj(journal) # Issue an HTTP success response.status_int = 200 return "OK"
def delete(self, id=None): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) idea = h.fetch_obj(Idea, id, new_id=True) h.delete_obj(idea) # Issue an HTTP success response.status_int = 200 return "OK"
def _delete_evaluation(self, evaltype, id, id2, uid=None, username=None): id2 = request.params.get('id2', id2) uid = request.params.get('uid', uid) username = request.params.get('username', username) evaluation = self._get_evaluation(evaltype, id, id2, uid, username, autoCreate=False) if not evaluation: abort(404) current_uid = h.get_user(request.environ['REMOTE_USER']).ID if evaluation.uid != current_uid and not h.auth.is_admin(): abort(401) h.delete_obj(evaluation) response.status_int = 200 return "OK"
def process(self): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) c.sepdirnew = False c.alreadysepdir = False action = request.params.get('action', None) action2 = request.params.get('action2', None) if action2: action = action2 q = request.params.get('label', None) label = q searchpattern = request.params.get('searchpattern', None) searchstring = request.params.get('searchstring', None) sep_dir = request.params.get('sep_dir', None) ioru = request.params.get('ioru', 'u') print "***" print "sep_dir is " print sep_dir print "and label is " print q print "***" values = dict(request.params) c.found = values.get('found', False) c.custom = values.get('custom', False) c.new = values.get('new', False) #ADD ACTION -- add a new entity (id/label cannot already exist) if action=='Add': #lowercase label and check to see whether it is valid #if so commit idea with standard pluralizations as searchpattern and give user a message that add was successful q = q.lower() #check to see whether label already exists idea_q = Session.query(Idea) # Check for query o = Idea.label.like(q) idea_q = idea_q.filter(o) # if 0 results, proceed to add idea if idea_q.count() == 0: print "***action add, idea q count == 0" #if no exact match for label, create new object with that label to add idea_add = Idea(q) #add searchstring = label idea_add.searchstring = q #add pluralizations to existing searchpatterns idea_add.searchpatterns = idea_add.pluralize() #setup the search string list c.idea = idea_add c.search_string_list = c.idea.setup_SSL() #setup sep_dir if present if sep_dir: c.idea.sep_dir = sep_dir #commit #take user to disambiguation page if the label contains an 'and' #otherwise, commit idea Session.add(idea_add) Session.flush() Session.commit() c.found = True something = 1 else: #already a match; give user error message that they should edit the preexisting page, and send them back to the submit idea #for edit page print "****action add, idea_q.count() not equal 0" c.message = "Idea with that name already exists in database; please edit the existing entry (returned below) or try a new label." c.idea = idea_q.first() c.search_string_list = c.idea.setup_SSL() return render('admin/idea-edit.html') c.message = "Idea added successfully." return render('admin/idea-edit.html') #Modify action -- edit an existing entry, id must exist elif action == 'Modify': #retrieve entity corresponding to id c.idea = h.fetch_obj(Idea, values['ID']) changed = False #generate searchpattern from searchstring if not already provided; current value stored in searchpattern, generate from searchstring if null #update parameters with form values if c.idea.sep_dir != values['sep_dir']: c.idea.sep_dir = values['sep_dir'] changed = True if c.idea.label != label: c.idea.label = label changed = True if not c.custom: if c.idea.searchstring != s.convertSS(searchstring, ioru)[0]: c.idea.searchstring = s.convertSS(searchstring, ioru)[0] #add default pluralizations to searchpatterns for label in c.idea.pluralize(): if label not in c.idea.searchpatterns: c.idea.searchpatterns.append(label) changed = True else: searchpatterns = [] for k, v in values.items(): key = "" if k.startswith('searchpatterns'): varname, num = k.split('.') key = 'delsearchpattern.%s'%(num) keyval = request.params.get(key, False) if not keyval: searchpatterns.append(v) if values['newsearchpattern']: searchpatterns.append(values['newsearchpattern']) changed = True #do manually edited searchpatterns first, so we don't write over them with the new default ones if the searchstring has been changed if c.idea.searchpatterns != searchpatterns: c.idea.searchpatterns = searchpatterns changed = True if c.idea.searchstring != searchstring: c.idea.searchstring = searchstring #add default pluralizations for new searchstring as well for label in c.idea.pluralize(): if label not in c.idea.searchpatterns: c.idea.searchpatterns.append(label) changed = True #make sure that searchpattern and searchstring are not shared by another entity #print "searchpatterns is " #print searchpatterns #print "c.idea.searchpatterns is" #print c.idea.searchpatterns #commit changes Session.flush() Session.commit() #return success message if changed == True: c.message = "Idea modified successfully." else: c.message = "No change required; idea not modified." c.found = True c.search_string_list = c.idea.setup_SSL() #prepare form return render('admin/idea-edit.html') #Delete action -- Delete an existing entity (id must exist) elif action=='Delete': c.idea = h.fetch_obj(Idea, values['ID']) c.message = "Idea # " + values['ID'] + " ("+ c.idea.label + ") deleted; please search for a new entity label on the left." h.delete_obj(c.idea) Session.flush() Session.commit() return render('admin/idea-edit.html') #use custom searchstring action elif action=='Use Custom Searchstring/Searchpattern': #toggle the c.custom to True and re-render form with htmlfill c.custom = True c.idea = h.fetch_obj(Idea, values['ID']) c.found = True c.message = 'Enter custom searchstring for ' + c.idea.label + "." return render('admin/idea-edit.html') #use standard searchstring action elif action=='Use Standard Searchstring/Searchpattern': #toggle the c.custom to False and re-render form with htmlfill c.custom = False c.idea = h.fetch_obj(Idea, values['ID']) c.found = True c.search_string_list = c.idea.setup_SSL() c.message = 'Now displaying standard searchstring options for ' + c.idea.label + "." return render('admin/idea-edit.html') else: raise Exception('I don\'t know how you got here, but you shouldn\'t be here...please start at the main page. Invalid action %s'%action)
def process(self, id=None): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) c.sepdirnew = False c.alreadysepdir = False label = request.params.get('label', None) id = request.params.get('ID', id) sep_dir = request.params.get('sep_dir', None) URL = request.params.get('URL', None) language = request.params.get('language', None) queries = [request.params.get('queries', None)] openAccess = request.params.get('openAccess', None) active = request.params.get('active', None) student = request.params.get('student', None) ISSN = request.params.get('ISSN', None) action = request.params.get('action', None) action2 = request.params.get('action2', None) if action2: action = action2 values = dict(request.params) #abbrs = [request.params.get('abbrs', None)] abbrs = [] queries = [] for k, v in values.items(): key = "" if k.startswith('abbrs'): varname, num = k.split('.') key = 'delabbr.%s'%(num) keyval = request.params.get(key, False) if not keyval: abbrs.append(v) elif k.startswith('queries'): varname, num = k.split('.') key = 'delquer.%s'%(num) keyval = request.params.get(key, False) if not keyval: queries.append(v) if action=="Add": journal_add = Journal() journal_add.label = label #setup search string and search pattern journalname = journal_add.label journalname_q = Session.query(Entity) o = Entity.searchpattern.like('( '+ journalname + ' )') journalname_q = journalname_q.filter(o).order_by(func.length(Entity.label)) if journalname_q.count() == 0: journal_add.searchpattern = "( " + journalname + " )" journal_add.searchstring = journalname else: journal_add.searchpattern = "( " + label + " )" journal_add.searchcstring = label #reset old journal pattern to whole name too to avoid conflict oldjournal = h.fetch_obj(Journal, journalname_q.first().ID) oldjournal.searchpattern = "( " + oldjournal.label + " )" oldjournal.searchstring = oldjournal.label Session.add(oldjournal) if sep_dir: journal_add.sep_dir = sep_dir c.journal = journal_add Session.add(journal_add) Session.flush() Session.commit() c.found = True c.message = "Journal " + c.journal.label + " added successfully." return render ('admin/journal-edit.html') elif action=="Modify": c.journal = h.fetch_obj(Journal, id) c.found = True changed = False #set values from form if c.journal.label != label: c.journal.label = label changed = True if c.journal.sep_dir != sep_dir: c.journal.sep_dir = sep_dir changed = True if c.journal.URL != URL: c.journal.URL = URL changed = True if c.journal.language != language: c.journal.language = language changed = True if c.journal.abbrs != abbrs: c.journal.abbrs = abbrs changed = True if c.journal.queries != queries: c.journal.queries = queries changed = True if c.journal.openAccess != openAccess: c.journal.openAccess = openAccess changed = True if c.journal.active != active: c.journal.active = active changed = True if c.journal.student != student: c.journal.student = student changed = True if c.journal.ISSN != ISSN: c.journal.ISSN = ISSN changed = True if values['newabbr']: c.journal.abbrs.append(values['newabbr']) changed = True if values['newquery']: c.journal.queries.append(values['newquery']) changed = True #commit changes Session.flush() Session.commit() if changed: c.message = "Journal " + c.journal.label + " modified successfully." else: c.message = "No change required; Journal " + c.journal.label + " not modified." return render ('admin/journal-edit.html') elif action == "Delete": c.journal = h.fetch_obj(Journal, values['ID']) c.message = "Journal # " + values['ID'] + " ("+ c.journal.label + ") deleted; please search for a new entity label on the left." h.delete_obj(c.journal) Session.flush() Session.commit() c.found = False return render('admin/journal-edit.html')
def process(self, id=None): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) c.sepdirnew = False c.alreadysepdir = False label = request.params.get('label', None) id = request.params.get('ID', id) sep_dir = request.params.get('sep_dir', None) action = request.params.get('action', None) action2 = request.params.get('action2', None) if action2: action = action2 values = dict(request.params) if action == "Add": thinker_add = Thinker(label) thinker_add.label = label #setup search string and search pattern lastname = thinker_add.label.split(' ').pop() lastname_q = Session.query(Entity) o = Entity.searchstring.like(lastname) lastname_q = lastname_q.filter(o).order_by( func.length(Entity.label)) if lastname_q.count() == 0: #if there's no match currently to last name, can use last name alone as searchpattern/searchstring thinker_add.searchpatterns.append(lastname) thinker_add.searchstring = lastname else: #otherwise, we need to use the whole name for both, and reset the other pattern to full name too thinker_add.searchpatterns.append(label) thinker_add.searchstring = label #reset old thinker pattern to whole name too to avoid conflict oldthinker = h.fetch_obj(Thinker, lastname_q.first().ID) oldthinker.searchpatterns = [oldthinker.label] oldthinker.searchstring = oldthinker.label Session.add(oldthinker) if sep_dir: thinker_add.sep_dir = sep_dir c.thinker = thinker_add Session.add(thinker_add) Session.flush() Session.commit() c.found = True c.message = "Thinker " + c.thinker.label + " added successfully." return render('admin/thinker-edit.html') elif action == "Modify": c.thinker = h.fetch_obj(Thinker, id) c.found = True changed = False searchpatterns = [] for k, v in values.items(): key = "" if k.startswith('searchpatterns'): varname, num = k.split('.') key = 'delsearchpattern.%s' % (num) keyval = request.params.get(key, False) if not keyval: searchpatterns.append(v) if values['newsearchpattern']: searchpatterns.append(values['newsearchpattern']) changed = True #do manually edited searchpatterns first, so we don't write over them with the new default ones if the searchstring has been changed if c.thinker.searchpatterns != searchpatterns: c.thinker.searchpatterns = searchpatterns changed = True #set values from form if c.thinker.name != values['name']: c.thinker.name = values['name'] changed = True if c.thinker.label != values['label']: c.thinker.name = values['label'] changed = True if c.thinker.searchstring != values['searchstring']: c.thinker.searchstring = values['searchstring'] changed = True if c.thinker.sep_dir != values['sep_dir']: c.thinker.sep_dir = values['sep_dir'] changed = True if c.thinker.wiki != values['wiki']: c.thinker.wiki = values['wiki'] changed = True if c.thinker.birth_day != values['birth_day']: c.thinker.birth_day = values['birth_day'] changed = True c.thinker.birth_day = values['birth_day'] if c.thinker.death_day != values['death_day']: c.thinker.death_day = values['death_day'] changed = True if c.thinker.birth_month != values['birth_month']: c.thinker.birth_month = values['birth_month'] changed = True if c.thinker.death_month != values['death_month']: c.thinker.death_month = values['death_month'] changed = True if not (c.thinker.birth_year == values['birth_year'] + " " + values['bornbc']): if c.thinker.birth_year != values['birth_year']: c.thinker.birth_year = values['birth_year'] changed = True if c.thinker.birth_year and values['bornbc'] and not re.search( "(BC)|(AD)", c.thinker.birth_year): c.thinker.birth_year = c.thinker.birth_year + " " + values[ 'bornbc'] changed = True if not (c.thinker.death_year == values['death_year'] + " " + values['diedbc']): if c.thinker.death_year != values['death_year']: c.thinker.death_year = values['death_year'] changed = True if c.thinker.death_year and values['diedbc'] and not re.search( "(BC)|(AD)", c.thinker.death_year): c.thinker.death_year = c.thinker.death_year + " " + values[ 'diedbc'] changed = True #commit changes Session.flush() Session.commit() if changed: c.message = "Thinker " + c.thinker.label + " modified successfully." else: c.message = "No changes detected. Thinker " + c.thinker.label + " not modified." return render('admin/thinker-edit.html') elif action == "Delete": c.thinker = h.fetch_obj(Thinker, values['ID']) c.message = "Thinker # " + values[ 'ID'] + " (" + c.thinker.label + ") deleted; please search for a new entity label on the left." h.delete_obj(c.thinker) Session.flush() Session.commit() c.found = False return render('admin/thinker-edit.html')
def process(self, id=None): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) c.sepdirnew = False c.alreadysepdir = False label = request.params.get('label', None) id = request.params.get('ID', id) sep_dir = request.params.get('sep_dir', None) URL = request.params.get('URL', None) language = request.params.get('language', None) queries = [request.params.get('queries', None)] openAccess = request.params.get('openAccess', None) active = request.params.get('active', None) student = request.params.get('student', None) ISSN = request.params.get('ISSN', None) action = request.params.get('action', None) action2 = request.params.get('action2', None) if action2: action = action2 values = dict(request.params) #abbrs = [request.params.get('abbrs', None)] abbrs = [] queries = [] for k, v in values.items(): key = "" if k.startswith('abbrs'): varname, num = k.split('.') key = 'delabbr.%s' % (num) keyval = request.params.get(key, False) if not keyval: abbrs.append(v) elif k.startswith('queries'): varname, num = k.split('.') key = 'delquer.%s' % (num) keyval = request.params.get(key, False) if not keyval: queries.append(v) if action == "Add": journal_add = Journal() journal_add.label = label #setup search string and search pattern journalname = journal_add.label journalname_q = Session.query(Entity) o = Entity.searchpattern.like('( ' + journalname + ' )') journalname_q = journalname_q.filter(o).order_by( func.length(Entity.label)) if journalname_q.count() == 0: journal_add.searchpattern = "( " + journalname + " )" journal_add.searchstring = journalname else: journal_add.searchpattern = "( " + label + " )" journal_add.searchcstring = label #reset old journal pattern to whole name too to avoid conflict oldjournal = h.fetch_obj(Journal, journalname_q.first().ID) oldjournal.searchpattern = "( " + oldjournal.label + " )" oldjournal.searchstring = oldjournal.label Session.add(oldjournal) if sep_dir: journal_add.sep_dir = sep_dir c.journal = journal_add Session.add(journal_add) Session.flush() Session.commit() c.found = True c.message = "Journal " + c.journal.label + " added successfully." return render('admin/journal-edit.html') elif action == "Modify": c.journal = h.fetch_obj(Journal, id) c.found = True changed = False #set values from form if c.journal.label != label: c.journal.label = label changed = True if c.journal.sep_dir != sep_dir: c.journal.sep_dir = sep_dir changed = True if c.journal.URL != URL: c.journal.URL = URL changed = True if c.journal.language != language: c.journal.language = language changed = True if c.journal.abbrs != abbrs: c.journal.abbrs = abbrs changed = True if c.journal.queries != queries: c.journal.queries = queries changed = True if c.journal.openAccess != openAccess: c.journal.openAccess = openAccess changed = True if c.journal.active != active: c.journal.active = active changed = True if c.journal.student != student: c.journal.student = student changed = True if c.journal.ISSN != ISSN: c.journal.ISSN = ISSN changed = True if values['newabbr']: c.journal.abbrs.append(values['newabbr']) changed = True if values['newquery']: c.journal.queries.append(values['newquery']) changed = True #commit changes Session.flush() Session.commit() if changed: c.message = "Journal " + c.journal.label + " modified successfully." else: c.message = "No change required; Journal " + c.journal.label + " not modified." return render('admin/journal-edit.html') elif action == "Delete": c.journal = h.fetch_obj(Journal, values['ID']) c.message = "Journal # " + values[ 'ID'] + " (" + c.journal.label + ") deleted; please search for a new entity label on the left." h.delete_obj(c.journal) Session.flush() Session.commit() c.found = False return render('admin/journal-edit.html')
def process(self, id=None): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) c.sepdirnew = False c.alreadysepdir = False label = request.params.get('label', None) id = request.params.get('ID', id) sep_dir = request.params.get('sep_dir', None) action = request.params.get('action', None) action2 = request.params.get('action2', None) if action2: action = action2 values = dict(request.params) if action=="Add": school_of_thought_add = model.SchoolOfThought(label) #school_of_thought_add.label = label #setup search string and search pattern school_of_thoughtname = school_of_thought_add.label school_of_thoughtname_q = model.meta.Session.query(model.Entity) o = model.Entity.label.like('( '+ school_of_thoughtname + ' )') school_of_thoughtname_q = school_of_thoughtname_q.filter(o).order_by(func.length(model.Entity.label)) if school_of_thoughtname_q.count() == 0: school_of_thought_add.searchpattern = "( " + school_of_thoughtname + " )" school_of_thought_add.searchstring = school_of_thoughtname else: school_of_thought_add.searchpattern = "( " + label + " )" school_of_thought_add.searchcstring = label #reset old school_of_thought pattern to whole name too to avoid conflict oldschool_of_thought = h.fetch_obj(model.SchoolOfThought, school_of_thoughtname_q.first().ID) oldschool_of_thought.searchpattern = "( " + oldschool_of_thought.label + " )" oldschool_of_thought.searchstring = oldschool_of_thought.label meta.Session.add(oldschool_of_thought) if sep_dir: school_of_thought_add.sep_dir = sep_dir c.school_of_thought = school_of_thought_add meta.Session.add(school_of_thought_add) meta.Session.flush() meta.Session.commit() c.found = True c.message = "SchoolOfThought " + c.school_of_thought.label + " added successfully." return render ('admin/school_of_thought-edit.html') elif action=="Modify": c.school_of_thought = h.fetch_obj(model.SchoolOfThought, id) c.found = True changed = False #set values from form if c.school_of_thought.label != label: c.school_of_thought.label = label changed = True if c.school_of_thought.sep_dir != sep_dir: c.school_of_thought.sep_dir = sep_dir changed = True #commit changes meta.Session.flush() meta.Session.commit() if changed: c.message = "SchoolOfThought " + c.school_of_thought.label + " modified successfully." else: c.message = "No change needed; SchoolOfThought " + c.school_of_thought.label + " not modified." return render ('admin/school_of_thought-edit.html') elif action == "Delete": c.school_of_thought = h.fetch_obj(model.SchoolOfThought, values['ID']) c.message = "SchoolOfThought # " + values['ID'] + " ("+ c.school_of_thought.label + ") deleted; please search for a new entity label on the left." h.delete_obj(c.school_of_thought) meta.Session.flush() meta.Session.commit() c.found = False return render('admin/school_of_thought-edit.html')
def process(self, id=None): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) c.sepdirnew = False c.alreadysepdir = False label = request.params.get('label', None) id = request.params.get('ID', id) sep_dir = request.params.get('sep_dir', None) action = request.params.get('action', None) action2 = request.params.get('action2', None) if action2: action = action2 values = dict(request.params) if action=="Add": work_add = model.Work(label) #work_add.label = label #setup search string and search pattern workname = work_add.label workname_q = model.meta.Session.query(model.Entity) o = model.Entity.label.like('( '+ workname + ' )') workname_q = workname_q.filter(o).order_by(func.length(model.Entity.label)) if workname_q.count() == 0: work_add.searchpattern = "( " + workname + " )" work_add.searchstring = workname else: work_add.searchpattern = "( " + label + " )" work_add.searchstring = label #reset old work pattern to whole name too to avoid conflict oldwork = h.fetch_obj(model.Work, workname_q.first().ID) oldwork.searchpattern = "( " + oldwork.label + " )" oldwork.searchstring = oldwork.label meta.Session.add(oldwork) if sep_dir: work_add.sep_dir = sep_dir c.work = work_add meta.Session.add(work_add) meta.Session.flush() meta.Session.commit() c.found = True c.message = "Work " + c.work.label + " added successfully." return render ('admin/work-edit.html') elif action=="Modify": c.work = h.fetch_obj(model.Work, id) c.found = True changed = False #set values from form if c.work.label != label: c.work.label = label changed = True if c.work.sep_dir != sep_dir: c.work.sep_dir = sep_dir changed = True #commit changes meta.Session.flush() meta.Session.commit() if changed: c.message = "Work " + c.work.label + " modified successfully." else: c.message = "No change required; Work " + c.work.label + " not modified." return render ('admin/work-edit.html') elif action == "Delete": c.work = h.fetch_obj(model.Work, values['ID']) c.message = "Work # " + values['ID'] + " ("+ c.work.label + ") deleted; please search for a new entity label on the left." h.delete_obj(c.work) meta.Session.flush() meta.Session.commit() c.found = False return render('admin/work-edit.html')
def process(self, id=None): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) c.sepdirnew = False c.alreadysepdir = False label = request.params.get('label', None) id = request.params.get('ID', id) sep_dir = request.params.get('sep_dir', None) action = request.params.get('action', None) action2 = request.params.get('action2', None) if action2: action = action2 values = dict(request.params) if action=="Add": thinker_add = Thinker(label) thinker_add.label = label #setup search string and search pattern lastname = thinker_add.label.split(' ').pop() lastname_q = Session.query(Entity) o = Entity.searchstring.like(lastname) lastname_q = lastname_q.filter(o).order_by(func.length(Entity.label)) if lastname_q.count() == 0: #if there's no match currently to last name, can use last name alone as searchpattern/searchstring thinker_add.searchpatterns.append(lastname) thinker_add.searchstring = lastname else: #otherwise, we need to use the whole name for both, and reset the other pattern to full name too thinker_add.searchpatterns.append(label) thinker_add.searchstring = label #reset old thinker pattern to whole name too to avoid conflict oldthinker = h.fetch_obj(Thinker, lastname_q.first().ID) oldthinker.searchpatterns = [oldthinker.label] oldthinker.searchstring = oldthinker.label Session.add(oldthinker) if sep_dir: thinker_add.sep_dir = sep_dir c.thinker = thinker_add Session.add(thinker_add) Session.flush() Session.commit() c.found = True c.message = "Thinker " + c.thinker.label + " added successfully." return render ('admin/thinker-edit.html') elif action=="Modify": c.thinker = h.fetch_obj(Thinker, id) c.found = True changed = False searchpatterns = [] for k, v in values.items(): key = "" if k.startswith('searchpatterns'): varname, num = k.split('.') key = 'delsearchpattern.%s'%(num) keyval = request.params.get(key, False) if not keyval: searchpatterns.append(v) if values['newsearchpattern']: searchpatterns.append(values['newsearchpattern']) changed = True #do manually edited searchpatterns first, so we don't write over them with the new default ones if the searchstring has been changed if c.thinker.searchpatterns != searchpatterns: c.thinker.searchpatterns = searchpatterns changed = True #set values from form if c.thinker.name != values['name']: c.thinker.name = values['name'] changed = True if c.thinker.label != values['label']: c.thinker.name = values['label'] changed = True if c.thinker.searchstring != values['searchstring']: c.thinker.searchstring = values['searchstring'] changed = True if c.thinker.sep_dir != values['sep_dir']: c.thinker.sep_dir = values['sep_dir'] changed = True if c.thinker.wiki != values['wiki']: c.thinker.wiki = values['wiki'] changed = True if c.thinker.birth_day != values['birth_day']: c.thinker.birth_day = values['birth_day'] changed = True c.thinker.birth_day = values['birth_day'] if c.thinker.death_day != values['death_day']: c.thinker.death_day = values['death_day'] changed = True if c.thinker.birth_month != values['birth_month']: c.thinker.birth_month = values['birth_month'] changed = True if c.thinker.death_month != values['death_month']: c.thinker.death_month = values['death_month'] changed = True if not (c.thinker.birth_year == values['birth_year'] + " " + values['bornbc']): if c.thinker.birth_year != values['birth_year']: c.thinker.birth_year = values['birth_year'] changed = True if c.thinker.birth_year and values['bornbc'] and not re.search("(BC)|(AD)",c.thinker.birth_year): c.thinker.birth_year = c.thinker.birth_year + " " + values['bornbc'] changed = True if not (c.thinker.death_year == values['death_year'] + " " + values['diedbc']): if c.thinker.death_year != values['death_year']: c.thinker.death_year = values['death_year'] changed = True if c.thinker.death_year and values['diedbc']and not re.search("(BC)|(AD)",c.thinker.death_year): c.thinker.death_year = c.thinker.death_year + " " + values['diedbc'] changed = True #commit changes Session.flush() Session.commit() if changed: c.message = "Thinker " + c.thinker.label + " modified successfully." else: c.message = "No changes detected. Thinker " + c.thinker.label + " not modified." return render ('admin/thinker-edit.html') elif action == "Delete": c.thinker = h.fetch_obj(Thinker, values['ID']) c.message = "Thinker # " + values['ID'] + " ("+ c.thinker.label + ") deleted; please search for a new entity label on the left." h.delete_obj(c.thinker) Session.flush() Session.commit() c.found = False return render('admin/thinker-edit.html')
def process(self, id=None): if not h.auth.is_logged_in(): abort(401) if not h.auth.is_admin(): abort(403) c.sepdirnew = False c.alreadysepdir = False label = request.params.get('label', None) id = request.params.get('ID', id) sep_dir = request.params.get('sep_dir', None) action = request.params.get('action', None) action2 = request.params.get('action2', None) if action2: action = action2 values = dict(request.params) if action == "Add": school_of_thought_add = model.SchoolOfThought(label) #school_of_thought_add.label = label #setup search string and search pattern school_of_thoughtname = school_of_thought_add.label school_of_thoughtname_q = model.meta.Session.query(model.Entity) o = model.Entity.label.like('( ' + school_of_thoughtname + ' )') school_of_thoughtname_q = school_of_thoughtname_q.filter( o).order_by(func.length(model.Entity.label)) if school_of_thoughtname_q.count() == 0: school_of_thought_add.searchpattern = "( " + school_of_thoughtname + " )" school_of_thought_add.searchstring = school_of_thoughtname else: school_of_thought_add.searchpattern = "( " + label + " )" school_of_thought_add.searchcstring = label #reset old school_of_thought pattern to whole name too to avoid conflict oldschool_of_thought = h.fetch_obj( model.SchoolOfThought, school_of_thoughtname_q.first().ID) oldschool_of_thought.searchpattern = "( " + oldschool_of_thought.label + " )" oldschool_of_thought.searchstring = oldschool_of_thought.label meta.Session.add(oldschool_of_thought) if sep_dir: school_of_thought_add.sep_dir = sep_dir c.school_of_thought = school_of_thought_add meta.Session.add(school_of_thought_add) meta.Session.flush() meta.Session.commit() c.found = True c.message = "SchoolOfThought " + c.school_of_thought.label + " added successfully." return render('admin/school_of_thought-edit.html') elif action == "Modify": c.school_of_thought = h.fetch_obj(model.SchoolOfThought, id) c.found = True changed = False #set values from form if c.school_of_thought.label != label: c.school_of_thought.label = label changed = True if c.school_of_thought.sep_dir != sep_dir: c.school_of_thought.sep_dir = sep_dir changed = True #commit changes meta.Session.flush() meta.Session.commit() if changed: c.message = "SchoolOfThought " + c.school_of_thought.label + " modified successfully." else: c.message = "No change needed; SchoolOfThought " + c.school_of_thought.label + " not modified." return render('admin/school_of_thought-edit.html') elif action == "Delete": c.school_of_thought = h.fetch_obj(model.SchoolOfThought, values['ID']) c.message = "SchoolOfThought # " + values[ 'ID'] + " (" + c.school_of_thought.label + ") deleted; please search for a new entity label on the left." h.delete_obj(c.school_of_thought) meta.Session.flush() meta.Session.commit() c.found = False return render('admin/school_of_thought-edit.html')