Пример #1
0
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())
Пример #2
0
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())
Пример #3
0
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())