def editIdea(title): #sends the idea in title to the same template as add idea #but all appropriate information is filled in if session.get('logged_in'): if request.method=="POST": #change the title, then the body, then the tags, redirect to display the new idea #any errors will flash why, then redirect to display the idea in its current state newTitle=request.form['title'].lower() if idea_box.changeTitle(session['username'],title,newTitle): if idea_box.changeIdea(session['username'],newTitle,request.form['body']): if idea_box.changeTags(session['username'],newTitle,request.form['tags']): flash("Idea change Success!") else: flash("Could not change tags") else: flash("Could not change body") else: flash("Could not change title") results=idea_search.ideaQuery(session['username'],title.lower(),"","").all()[0] return render_template('editIdea.html',idea=results) #display the edited idea results=idea_search.ideaQuery(session['username'],newTitle,"","").all() return render_template('displayResults.html',results=results) else: #we need the edit data, send to edit page results=idea_search.ideaQuery(session['username'],title.lower(),"","").all()[0] return render_template('editIdea.html',idea=results) else: return redirect(url_for('welcome.html'))
def genericTest(username,title,contains,tags): try: #create a string describing what we're testing str="" if username<>"": str=str+"username: %s\n"%username else:str=str+"username: none\n" if title<>"": str=str+"title: %s\n"%title else:str=str+"title: none\n" if contains<>"": str=str+"contains: %s\n"%contains else:str=str+"contains: none\n" if tags<>"": str=str+"tags: %s\n"%tags if andor==1: str=str+" and" else: str=str+" or" else:str=str+"tags: none\n" print "Attempting Query Test of-\n",str session=idea_box.createAll() #run the test results= ideaQuery(username,title,contains,tags,session) for thing in results: #print '\nresult ',results.all().index(thing) print thing print "Number of results: ",len(results.all()) session.close() except: print "error Query Test: ",str raise else: print "Query test: %s COMPLETE"%str
def searchIdea(): #executes a search and displays teh results if session.get('logged_in'):#need to verify logged in print 'hello' if request.method=='POST': #search and display results=idea_search.ideaQuery(session['username'],request.form['title'],request.form['body'],request.form['tags']).all() return render_template('displayResults.html',results=results) else: return render_template('searchIdea.html') else: return redirect(url_for('welcome'))
def deleteIdea(title): #deletes the idea from teh database, no backsies! if session.get('logged_in'): #attempt to delete idea and show results if idea_box.deleteIdea(session['username'],title.lower()): flash("Idea deleted") return redirect(url_for('displayAll')) else: #if something fails, explain and show idea flash("Could not delete") results=idea_search.ideaQuery(session['username'],title.lower(),"","").all() return render_template('displayResults.html',results=results) else: return redirect(url_for('welcome'))
def addIdea(): #checks if user is logged in, if title is unique #if so, creates idea, then displays it #else flashes error if session.get('logged_in'):#need to verify logged in if request.method=='POST': if idea_box.uniqueTitle(session['username'],request.form['title'].lower()): #checks passed, create the idea idea_box.createIdea(session['username'],request.form['title'].lower(),request.form['body'],request.form['tags']) flash("New Idea Added!") results=idea_search.ideaQuery(session['username'],request.form['title'],"","").all() return render_template('displayResults.html',results=results) #display errors and redirect accordingly else: flash('Title already exists') else: return redirect(url_for('welcome')) return render_template('addIdea.html')
def displayAll(): if session.get('logged_in'):#need to verify logged in #all resutls displayed here results=idea_search.ideaQuery(session['username'],"","","").all() return render_template('displayResults.html', results=results) else: return redirect(url_for('welcome'))