def view_joke(jokeId=None, category=None): # If not logged in, redirect to login page if not session.get(key_email): return redirect(url_for('login')) the_joke = None if jokeId: the_joke = models.joke_by_jokeId(jokeId) elif category: the_joke = models.joke_by_category(category) else: the_joke = models.random_joke() title = the_joke.title content = the_joke.content categories = the_joke.categories jokeId = the_joke.jokeId privileged = session.get(key_userType) == user_privileged return render_template('view_joke.html', joke_title=title, joke_content=content, privileged=privileged, jokeId=jokeId)
def update_joke(): if not session.get(key_email): return redirect(url_for('login')) if session.get(key_userType) != user_privileged: return json.dumps( {'msg': 'Must be an elevated user to modify or delete a joke.'}) joke = request.get_json(force=True, silent=True) print joke print "joke_type: {}".format(type(joke)) if 'jokeId' not in joke or 'title' not in joke or 'content' not in joke: return json.dumps({'msg': 'Joke update failed'}) joke['jokeId'] = int(joke['jokeId']) the_joke = models.joke_by_jokeId(joke['jokeId']) if the_joke is None: return json.dumps({'msg': 'No joke found with that jokeId'}) print "JokeId: {}".format(joke['jokeId']) # Now, make direct modifications to the joke content and title the_joke.title = joke['title'] the_joke.content = joke['content'] # Save new joke to database models.update_joke(the_joke) return json.dumps({'redirect': url_for('view_joke')})
def update_joke(): # TODO: implement db update joke = request.get_json(force=True, silent=True) print joke print "joke_type: {}".format(type(joke)) if 'jokeId' not in joke or 'title' not in joke or 'content' not in joke: return json.dumps({'msg': 'Joke update failed'}) joke['jokeId'] = int(joke['jokeId']) the_joke = models.joke_by_jokeId(joke['jokeId']) if the_joke is None: return json.dumps({'msg': 'No joke found with that jokeId'}) print "JokeId: {}".format(joke['jokeId']) # Now, make direct modifications to the joke content and title the_joke.title = joke['title'] the_joke.content = joke['content'] # Save new joke to database models.update_joke(the_joke) return json.dumps({'redirect': url_for('view_joke')})