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))
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'))
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))
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'))