示例#1
0
def add_post():
    form = SubmitQuote(request.form)
    if request.method == 'POST' and form.validate():
        newPost = Post(form.quote.data)
        db_session.add(newPost)
        db_session.commit()
        return redirect(url_for('show_posts'))
    return render_template('add.html', form=form)
示例#2
0
def vote_post(action, post_id):
    editPost = Post.query.get(post_id)
    if action == 'up':
        editPost.ups += 1
    elif action == 'down':
        editPost.downs += 1
    else:
        return "you f****d up"
    editPost.score = calc_score(editPost.ups, editPost.downs, editPost.submitted_on)
    db_session.add(editPost)
    db_session.commit()
    return redirect(url_for('show_posts'))