Example #1
0
def comment_book(book_id):
    """ Создание комментариев к книгам"""
    # если пользователь не авторизован, кидаем его на страницу входа
    if 'username' not in session:
        return redirect('login')
    form = AddCommentForm()
    book = BooksModel(db.get_connection()).get(book_id)
    if not book:
        return render_template('error.html', loged=True, title='Ошибка')
    if form.validate_on_submit():
        # создать комментарий
        comment = Comment(book_id=book_id,
                          username=session['username'],
                          name=form.name.data,
                          text=form.text.data,
                          date=form.date.data,
                          book_name=book[1])
        db_comments.session.add(comment)
        db_comments.session.commit()
        # редирект на страницу книги
        return redirect('/book/' + str(book_id))
    return render_template("add_comment.html",
                           title='Добавить рецензию',
                           form=form,
                           loged=True)
Example #2
0
def post(title):
    post = Post.query.filter(Post.title == title).first()
    form = AddCommentForm()
    if form.validate_on_submit():
        comment = Comment(author_name=form.author_name.data, email=form.email.data,
                          content=form.content.data, post=post, pub_date=datetime.datetime.now())
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for("main.post", title=title))
    return render_template('post.html', post=post, form=form, title=title)
Example #3
0
def add_comment(post_id):
    comment_form = AddCommentForm()
    if comment_form.validate_on_submit():
        post = BlogPost.query.get(post_id)
        new_comment = Comment(body=comment_form.body.data,
                              author=current_user,
                              post=post)
        db.session.add(new_comment)
        db.session.commit()
        return redirect(url_for("show_post", post_id=post.id))

    return render_template("add-comment.html", form=comment_form)
Example #4
0
def add_comment():
    form = AddCommentForm()
    if form.validate_on_submit():
        comment_body = form.comment_body.data
        post_id = form.post_id.data

        new_comment = Comments(comment_body, post_id)

        db.session.add(new_comment)
        db.session.commit()

        return redirect(url_for('posts'))

    return render_template('add_comment.html', form=form)