예제 #1
0
def repost(post_id):
    post = Post.get_by_id(post_id)
    if post in current_user.reposts:
        current_user.reposts.remove(post)
    else:
        current_user.reposts.append(post)
    db_session.commit()
    return redirect(url_for('posts.view_post', post_id=post_id))
예제 #2
0
def view_post(post_id):
    post = Post.get_by_id(post_id)
    if post is not None:
        return render_template('viewpost.html', post=post, owner=post.owner,
                               comments=post.comments, comment_form=AddComment())
    else:
        flash('No post with given ID!', 'error')
        return redirect(url_for('main.hello'))
예제 #3
0
def new_comment(post_id):
    form = AddComment(request.form)
    if form.validate():
        comment = Comment(bleach.clean(form.comment.data), datetime.datetime.utcnow(), current_user.id, post_id)
        post = Post.get_by_id(post_id)
        post.comments.append(comment)
        db_session.commit()
    else:
        flash("Something went wrong. Make sure that your tweet's length is less than 140 characters", 'error')
    return redirect(url_for('posts.view_post', post_id=post_id))
예제 #4
0
def delete_post(post_id):
    post = Post.get_by_id(post_id)
    db_session.delete(post)
    db_session.commit()
    return redirect(url_for('main.hello'))