def post_topic(board_id, board_name): board = Board.objects(board_id=board_id).first() if board is None: abort(404) forum = board.forum form = PostTopicForm(request.form) if request.method == 'GET': return render_template('forum_post_topic.html', board=board, forum=forum, form=form) elif request.method == 'POST': if not form.validate(): return render_template('forum_post_topic.html', board=board, forum=forum, form=form) topic = Topic(title=form.title.data, author=current_user.to_dbref(), forum=forum, board=board) topic_edit = TopicEdit(title=topic.title, date=topic.date, announcement=topic.announcement, author=topic.author) topic.edits.append(topic_edit) topic.save() post = Post(author=current_user.to_dbref(), content=form.content.data, topic=topic, forum=forum, date=topic.date, is_op=True) post_edit = PostEdit(author=post.author, content=post.content, date=post.date) post.edits.append(post_edit) post.save() topic.op = post topic.date = post.date topic.save() return redirect(topic.get_url())
def post_ban_reply(ban_uid): reply_form = AppealReplyForm(request.form) ban = Ban.objects(uid=ban_uid).first() if ban is None: abort(404) if not user_can_post(current_user, ban): abort(403) appeal = ban.appeal if request.method == "POST" and reply_form.validate(): last_reply = AppealReply.objects(ban=ban).order_by('-created').first() # If the user just posted a reply, treat this as an edit of his previous post. if last_reply and last_reply.creator.name == current_user.name: last_reply.text += "\n- - -\n" + reply_form.text.data last_reply.edits.append(AppealEdit(text=last_reply.text, user=current_user.to_dbref())) last_reply.save() return redirect(url_for('bans.view_ban', ban_uid=ban_uid)) else: reply = AppealReply(creator=current_user.to_dbref(), text=reply_form.text.data, ban=ban) reply.edits.append(AppealEdit(text=reply_form.text.data, user=current_user.to_dbref())) reply.save() appeal.replies.append(reply) appeal.last = datetime.datetime.utcnow() ban.save() BanNotification.send_notifications(ban, action="reply") return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
def edit_post(post_id): form = PostEditForm(request.form) if not ObjectId.is_valid(post_id): abort(404) post = Post.objects(id=post_id).first() if post is None: abort(404) if not post.can_edit(current_user): abort(403) topic = post.topic board = topic.board forum = post.forum if request.method == "POST" and form.validate(): post_edit = PostEdit(author=current_user.to_dbref(), content=form.content.data, date=datetime.utcnow()) post.edits.append(post_edit) post.content = form.content.data post.save() return redirect(topic.get_url()) form.content.data = post.content return render_template("forum_post_edit.html", form=form, topic=topic, board=board, forum=forum)
def post_reply(topic_id, topic_name): topic = Topic.objects(topic_url_id=topic_id).first() if topic is None: abort(404) if not topic_name == topic.get_url_name(): return redirect(topic.get_url()) board = topic.board forum = board.forum form = TopicReplyForm(request.form) if request.method == 'GET': return render_template('forum_post_reply.html', forum=forum, board=board, topic=topic, form=form) elif request.method == 'POST': if not form.validate(): return render_template('forum_post_reply.html', forum=forum, board=board, topic=topic, form=form) post = Post(author=current_user.to_dbref(), content=form.content.data, topic=topic, forum=forum) post_edit = PostEdit(author=post.author, content=post.content, date=post.date) post.edits.append(post_edit) post.save() topic.update(set__users_read_topic=[], set__last_post_date=post.date) return redirect(topic.get_url())
def api_key_add(): form = AddApiKeyForm(request.form) key = ApiKey(owner=current_user.to_dbref(), label=form.label.data) key.save() flash("Key has been added.", category="success") return redirect(url_for('api.api_key_edit', key_id=key.id))
def api_key_settings_pane(): apikey_add_form = AddApiKeyForm(request.form) apikey_del_form = DelApiKeyForm(request.form) keys = ApiKey.objects(owner=current_user.to_dbref()) return render_template('api_settings_pane.html', settings_panels_structure=settings_panels_structure, keys=keys, apikey_add_form=apikey_add_form, apikey_del_form=apikey_del_form, title="API Keys - Developer - Settings")
def post_ban_reply(ban_uid): reply_form = AppealReplyForm(request.form) ban = Ban.objects(uid=ban_uid).first() if ban is None: abort(404) if not user_can_post(current_user, ban): abort(403) appeal = ban.appeal if request.method == "POST" and reply_form.validate(): last_reply = AppealReply.objects(ban=ban).order_by('-created').first() # If the user just posted a reply, treat this as an edit of his previous post. if last_reply and last_reply.creator.name == current_user.name: last_reply.text += "\n- - -\n" + reply_form.text.data last_reply.edits.append( AppealEdit(text=last_reply.text, user=current_user.to_dbref())) last_reply.save() return redirect(url_for('bans.view_ban', ban_uid=ban_uid)) else: reply = AppealReply(creator=current_user.to_dbref(), text=reply_form.text.data, ban=ban) reply.edits.append( AppealEdit(text=reply_form.text.data, user=current_user.to_dbref())) reply.save() appeal.replies.append(reply) appeal.last = datetime.datetime.utcnow() ban.save() BanNotification.send_notifications(ban, action="reply") return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
def appeal_reply_edit(appeal_reply_id): edit_form = AppealReplyTextEditForm(request.form) appeal_reply = AppealReply.objects(id=appeal_reply_id).first() if appeal_reply is None: abort(404) if not (current_user.has_permission("bans.appeal.manage") or (current_user.is_authenticated() and current_user == appeal_reply.creator)): abort(403) if request.method == "POST" and edit_form.validate(): appeal_reply.text = edit_form.text.data appeal_reply.edits.append(AppealEdit(text=edit_form.text.data, user=current_user.to_dbref())) appeal_reply.save() return redirect(url_for('bans.view_ban', ban_uid=appeal_reply.ban.uid))
def appeal_reply_edit(appeal_reply_id): edit_form = AppealReplyTextEditForm(request.form) appeal_reply = AppealReply.objects(id=appeal_reply_id).first() if appeal_reply is None: abort(404) if not (current_user.has_permission("bans.appeal.manage") or (current_user.is_authenticated() and current_user == appeal_reply.creator)): abort(403) if request.method == "POST" and edit_form.validate(): appeal_reply.text = edit_form.text.data appeal_reply.edits.append( AppealEdit(text=edit_form.text.data, user=current_user.to_dbref())) appeal_reply.save() return redirect(url_for('bans.view_ban', ban_uid=appeal_reply.ban.uid))
def add_payment(): if not current_user.has_permission('financial.payments'): abort(403) form = PaymentAddForm(request.form) if request.method == "POST": payment = PaymentTransaction() payment.amount = form.amount.data payment.period_begin = form.start_date.data payment.period_end = form.end_date.data payment.user = current_user.to_dbref() payment.note = form.note.data payment.save() return redirect(url_for('donations.donate')) return render_template("add_payment.html", form=form)
def view_topic(topic_id, topic_name, page): if page == 0: abort(404) topic_reply_form = TopicReplyForm() topic = Topic.objects(topic_url_id=topic_id).exclude().first() if topic is None: abort(404) if not topic_name == topic.get_url_name(): return redirect(topic.get_url()) if current_user.is_authenticated(): topic.update(add_to_set__users_read_topic=current_user.to_dbref()) board = topic.board forum = board.forum # Get our sorted posts and the number of posts. posts = Post.objects(topic=topic).order_by('+date') num_posts = len(posts) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(num_posts / float(POSTS_PER_PAGE))) if num_pages < page: if page == 1: return render_template('forum_topic_view.html', topic=topic, board=board, forum=forum, posts=posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=None, prev=None, links=[]) abort(404) # Compile the list of topics we want displayed. display_posts = posts.skip( (page - 1) * POSTS_PER_PAGE).limit(POSTS_PER_PAGE) # Find the links we want for the next/prev buttons if applicable. next_page = url_for( 'forum.view_topic', page=page + 1, **topic.get_url_info()) if page < num_pages else None prev_page = url_for( 'forum.view_topic', page=page - 1, **topic.get_url_info()) if page > 1 and not num_pages == 1 else None # Mash together a list of what pages we want linked to in the pagination bar. links = [] for page_mod in range(-min(PAGINATION_VALUE_RANGE, page - 1), min(PAGINATION_VALUE_RANGE, num_pages - page) + 1): num = page + page_mod links.append({ 'num': num, 'url': url_for('forum.view_topic', page=num, **topic.get_url_info()), 'active': (num == page) }) return render_template('forum_topic_view.html', topic=topic, board=board, forum=forum, posts=display_posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=next_page, prev=prev_page, links=links, markdown_escape=markdown_escape, post_edit=PostEditForm(), forum_menu_current=board.id, **forum_template_data(forum))
def view_topic(topic_id, topic_name, page): if page == 0: abort(404) topic_reply_form = TopicReplyForm() topic = Topic.objects(topic_url_id=topic_id).exclude().first() if topic is None: abort(404) if not topic_name == topic.get_url_name(): return redirect(topic.get_url()) if current_user.is_authenticated(): topic.update(add_to_set__users_read_topic=current_user.to_dbref()) board = topic.board forum = board.forum # Get our sorted posts and the number of posts. posts = Post.objects(topic=topic).order_by("+date") num_posts = len(posts) # Calculate the total number of pages and make sure the request is a valid page. num_pages = int(math.ceil(num_posts / float(POSTS_PER_PAGE))) if num_pages < page: if page == 1: return render_template( "forum_topic_view.html", topic=topic, board=board, forum=forum, posts=posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=None, prev=None, links=[], ) abort(404) # Compile the list of topics we want displayed. display_posts = posts.skip((page - 1) * POSTS_PER_PAGE).limit(POSTS_PER_PAGE) # Find the links we want for the next/prev buttons if applicable. next_page = url_for("forum.view_topic", page=page + 1, **topic.get_url_info()) if page < num_pages else None prev_page = ( url_for("forum.view_topic", page=page - 1, **topic.get_url_info()) if page > 1 and not num_pages == 1 else None ) # Mash together a list of what pages we want linked to in the pagination bar. links = [] for page_mod in range(-min(PAGINATION_VALUE_RANGE, page - 1), min(PAGINATION_VALUE_RANGE, num_pages - page) + 1): num = page + page_mod links.append( {"num": num, "url": url_for("forum.view_topic", page=num, **topic.get_url_info()), "active": (num == page)} ) return render_template( "forum_topic_view.html", topic=topic, board=board, forum=forum, posts=display_posts, topic_reply_form=topic_reply_form, total_pages=num_pages, current_page=page, next=next_page, prev=prev_page, links=links, markdown_escape=markdown_escape, post_edit=PostEditForm(), forum_menu_current=board.id, **forum_template_data(forum) )