def reply_post(topic_id, post_id): topic = Topic.query.filter_by(id=topic_id).first_or_404() post = Post.query.filter_by(id=post_id).first_or_404() if post.topic.forum.locked: flash("This forum is locked; you cannot submit new topics or posts.", "danger") return redirect(post.topic.forum.url) if post.topic.locked: flash("The topic is locked.", "danger") return redirect(post.topic.forum.url) if not can_post_reply(user=current_user, forum=topic.forum): flash("You do not have the permissions to post in this topic", "danger") return redirect(topic.forum.url) form = ReplyForm() if form.validate_on_submit(): if request.form['button'] == 'preview': return render_template("forum/new_post.html", topic=topic, form=form, preview=form.content.data) else: form.save(current_user, topic) return redirect(post.topic.url) else: form.content.data = '[quote]{}[/quote]'.format(post.content) return render_template("forum/new_post.html", topic=post.topic, form=form)
def view_topic(topic_id, slug=None): page = request.args.get('page', 1, type=int) topic = Topic.query.filter_by(id=topic_id).first() posts = Post.query.filter_by(topic_id=topic.id).\ order_by(Post.id.asc()).\ paginate(page, flaskbb_config['POSTS_PER_PAGE'], False) # Count the topic views topic.views += 1 # Update the topicsread status if the user hasn't read it forumsread = None if current_user.is_authenticated(): forumsread = ForumsRead.query.\ filter_by(user_id=current_user.id, forum_id=topic.forum.id).first() topic.update_read(current_user, topic.forum, forumsread) topic.save() form = None if can_post_reply(user=current_user, topic=topic): form = QuickreplyForm() if form.validate_on_submit(): post = form.save(current_user, topic) return view_post(post.id) return render_template("forum/topic.html", topic=topic, posts=posts, last_seen=time_diff(), form=form)
def new_post(topic_id, slug=None): topic = Topic.query.filter_by(id=topic_id).first_or_404() if not can_post_reply(user=current_user, topic=topic): flash("You do not have the permissions to post here", "danger") return redirect(topic.forum.url) form = ReplyForm() if form.validate_on_submit(): if request.form['button'] == 'preview': return render_template("forum/new_post.html", topic=topic, form=form, preview=form.content.data) else: post = form.save(current_user, topic) return view_post(post.id) return render_template("forum/new_post.html", topic=topic, form=form)
def new_post(topic_id, slug=None): topic = Topic.query.filter_by(id=topic_id).first_or_404() if not can_post_reply(user=current_user, topic=topic): flash(_("You do not have the permissions to post in this topic."), "danger") return redirect(topic.forum.url) form = ReplyForm() if form.validate_on_submit(): if "preview" in request.form: return render_template("forum/new_post.html", topic=topic, form=form, preview=form.content.data) else: post = form.save(current_user, topic) return view_post(post.id) return render_template("forum/new_post.html", topic=topic, form=form)
def view_topic(topic_id, slug=None): page = request.args.get('page', 1, type=int) # Fetch some information about the topic topic = Topic.query.filter_by(id=topic_id).first() # Count the topic views topic.views += 1 topic.save() # fetch the posts in the topic posts = Post.query.\ join(User, Post.user_id == User.id).\ filter(Post.topic_id == topic.id).\ add_entity(User).\ order_by(Post.id.asc()).\ paginate(page, flaskbb_config['POSTS_PER_PAGE'], False) # Update the topicsread status if the user hasn't read it forumsread = None if current_user.is_authenticated(): forumsread = ForumsRead.query.\ filter_by(user_id=current_user.id, forum_id=topic.forum.id).first() topic.update_read(current_user, topic.forum, forumsread) form = None if can_post_reply(user=current_user, topic=topic): form = QuickreplyForm() if form.validate_on_submit(): post = form.save(current_user, topic) return view_post(post.id) return render_template("forum/topic.html", topic=topic, posts=posts, last_seen=time_diff(), form=form)
def new_post(topic_id, slug=None): topic = Topic.query.filter_by(id=topic_id).first_or_404() if topic.forum.locked: flash("This forum is locked; you cannot submit new topics or posts.", "danger") return redirect(topic.forum.url) if topic.locked: flash("The topic is locked.", "danger") return redirect(topic.forum.url) if not can_post_reply(user=current_user, forum=topic.forum): flash("You do not have the permissions to delete the topic", "danger") return redirect(topic.forum.url) form = ReplyForm() if form.validate_on_submit(): post = form.save(current_user, topic) return view_post(post.id) return render_template("forum/new_post.html", topic=topic, form=form)
def view_topic(topic_id, slug=None): page = request.args.get('page', 1, type=int) topic = Topic.query.filter_by(id=topic_id).first() posts = Post.query.filter_by(topic_id=topic.id).\ order_by(Post.id.asc()).\ paginate(page, flaskbb_config['POSTS_PER_PAGE'], False) # Count the topic views topic.views += 1 # Update the topicsread status if the user hasn't read it forumsread = None if current_user.is_authenticated(): forumsread = ForumsRead.query.\ filter_by(user_id=current_user.id, forum_id=topic.forum.id).first() topic.update_read(current_user, topic.forum, forumsread) topic.save() form = None if not topic.locked \ and not topic.forum.locked \ and can_post_reply(user=current_user, forum=topic.forum): form = QuickreplyForm() if form.validate_on_submit(): post = form.save(current_user, topic) return view_post(post.id) return render_template("forum/topic.html", topic=topic, posts=posts, last_seen=time_diff(), form=form)
def reply_post(topic_id, post_id): topic = Topic.query.filter_by(id=topic_id).first_or_404() post = Post.query.filter_by(id=post_id).first_or_404() if not can_post_reply(user=current_user, topic=topic): flash(_("You do not have the permissions to post in this topic."), "danger") return redirect(topic.forum.url) form = ReplyForm() if form.validate_on_submit(): if "preview" in request.form: return render_template( "forum/new_post.html", topic=topic, form=form, preview=form.content.data ) else: form.save(current_user, topic) return redirect(post.topic.url) else: form.content.data = format_quote(post) return render_template("forum/new_post.html", topic=post.topic, form=form)