Пример #1
0
def comments_create(post_id, comment_id):
    if request.method == 'GET':
        return redirect(
            f'{url_for("posts_details", post_id=post_id)}#{comment_id or ""}')

    form = CommentForm(request.form)

    if not form.validate():
        return redirect(url_for('posts_details', post_id=post_id))

    parent = Comment.query.get(comment_id) if comment_id else None

    if parent and (str(parent.post_id) != post_id or parent.deleted):
        return redirect(url_for('posts_details', post_id=post_id))

    comment = Comment(form.content.data)
    comment.account_id = current_user.id
    comment.post_id = post_id
    comment.parent_id = comment_id

    with session_scope() as session:
        session.add(comment)
        session.commit()

        return redirect(
            f'{url_for("posts_details", post_id=post_id)}#{comment.id}')
Пример #2
0
def comments_create(submission_id):
    form = CommentForm(request.form)
    if form.validate():
        comment = Comment(form.text.data)
        comment.account_id = current_user.id
        comment.submission_id = submission_id
        db.session().add(comment)
        db.session().commit()
    return redirect(url_for('submissions_view', submission_id=submission_id))
Пример #3
0
def comment_create(recipe_id):
    form = CommentForm(request.form)
    if not form.validate():
        return redirect(url_for('recipe_get', recipe_id=recipe_id))

    c = Comment(form.text.data)
    c.account_id = current_user.id
    c.recipe_id = recipe_id

    db.session().add(c)
    db.session().commit()

    return redirect(url_for('recipe_get', recipe_id=recipe_id))
Пример #4
0
def comment_create(recipe_id):
    form = CommentForm(request.form)
    if not form.validate():
        return render_template("recipes/<recipe_id>/", form=form)

    c = Comment(form.text.data)
    c.account_id = current_user.id
    c.recipe_id = recipe_id

    db.session().add(c)
    db.session().commit()

    return redirect(url_for("recipes/<recipe_id>/"))
Пример #5
0
def comments_create():

    form = CommentForm(request.form)
    threadi = Thread.query.get(form.thread_id.data)

    if not form.validate():
        return redirect(url_for("show_thread", thread_id=threadi.id))

    comm = Comment(form.message.data)
    comm.account_id = current_user.id
    comm.thread_id = form.thread_id.data

    db.session().add(comm)
    db.session().commit()

    return redirect(url_for("show_thread", thread_id=threadi.id))
Пример #6
0
def comment_create(recipe_id):
    form = CommentForm(request.form)
    recipe = Recipe.query.get(recipe_id)

    if not form.validate():
        return render_template("comments/new_comment.html",
                               form=form,
                               recipe_id=recipe.id)

    comment = Comment(form.comment_text.data)
    comment.account_id = current_user.id
    comment.recipe_id = recipe.id

    db.session().add(comment)
    db.session().commit()

    return redirect(url_for("recipes_show_single", recipe_id=recipe.id))
Пример #7
0
def new_comment(post_id):

    form = CommentForm(request.form)
    if not form.validate():
        return render_template("/posts/post.html",
                               form=PostForm(),
                               post=Post.query.get(post_id),
                               commentform=form)

    c = Comment(form.comment.data)
    c.account_id = current_user.id
    c.post_id = post_id

    db.session.add(c)
    db.session.commit()

    return redirect(url_for('post_specific', post_id=post_id))
Пример #8
0
def comments_create(matchID):
    form = CommentForm(request.form)

    if not form.validate():
        return render_template(
            "comments/list.html",
            form=form,
            matches=Match.query.filter_by(id=matchID),
            comments=Comment.query.filter_by(matchid=matchID))

    c = Comment(form.content.data, matchID)
    c.account_id = current_user.id
    c.name = current_user.username
    db.session().add(c)
    db.session().commit()
    return render_template("comments/list.html",
                           form=form,
                           matches=Match.query.filter_by(id=matchID),
                           comments=Comment.query.filter_by(matchid=matchID))
Пример #9
0
def message_new_comment(channel_id, message_id):

    messageform = MessageForm(request.form)

    if not messageform.validate() or messageform.body.data.isspace():
        return redirect(
            url_for("message_index",
                    channel_id=channel_id,
                    message_id=message_id))

    comment = Comment(messageform.body.data, current_user.username)
    comment.message_id = message_id
    comment.account_id = current_user.id

    db.session().add(comment)
    db.session().commit()

    return redirect(
        url_for("message_index", channel_id=channel_id, message_id=message_id))
Пример #10
0
def comments_create(conversation_id):
    form = CommentForm(request.form)
    if not form.validate():
        return render_template(
            "conversations/viewOne.html",
            t=Conversation.query.get(conversation_id),
            form=form,
            conversation_comments=Conversation.find_comments_for_conversation(
                conversation_id),
            error=
            "Kommentin pituus tulee olla vähintään 1 merkki ja korkeintaan 512 merkkiä."
        )
    t = Comment(form.name.data)
    t.account_id = current_user.id
    t.conversation_id = conversation_id
    db.session().add(t)
    db.session().commit()

    return redirect(
        url_for("conversation_view", conversation_id=conversation_id))