Example #1
0
def new_comment(posts_id):
    posts = Post.query.filter_by(id = posts_id).first()
    form = CommentForm()

    if form.validate_on_submit():
        comment = form.comment.data

        new_comment = Comment(comment_content=comment,user_id=current_user.id, posts_id=posts_id)

        new_comment.save_comment()

        return redirect(url_for('comments.index'))
    title='New Comment'
    return render_template('new_comment.html',title=title,comment_form = form,posts_id=posts_id)
Example #2
0
def post(post_id):
    post = Post.query.get_or_404(post_id)
    form = CommentForm()
    return render_template('posts/full_post.html',
                           title=post.title,
                           post=post,
                           form=form)
Example #3
0
def new_comment(post_id):
    post = Post.query.get_or_404(post_id)
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(content=form.content.data,
                          author=form.author.data,
                          email=form.email.data,
                          site_url=form.site_url.data,
                          post_id=post.id)
        db.session.add(comment)
        db.session.commit()
        flash('Your comment has been added!', 'success')
        return redirect(url_for('posts.post', post_id=post.id))

    return render_template('posts/full_post.html',
                           title=post.title,
                           post=post,
                           form=form)
Example #4
0
def new_comment(blog_id):
    form = CommentForm()
    if form.validate_on_submit():
        blog = Blog.query.get(int(blog_id))
        coments = Comment.query.filter_by(user_id=current_user.id).all()
        commented_today = []
        blog_ids = []
        for comment in coments:
            if datetime.utcnow().__str__(
            )[:10] in comment.date_commented.__str__():
                commented_today.append(comment)
                blog_ids.append(comment.blog_id)

        if blog.bloggedBy == current_user:
            flash('You cannot comment on your own blog', 'danger')
        elif len(commented_today) >= 3:
            flash('You cannot comment more than three times per day', 'danger')
        elif blog_id in blog_ids:
            flash(
                'You cannot comment on a particular blog more than once per day',
                'danger')
        else:
            comment = Comment(comment=form.comment.data,
                              sentiment=form.sentiment.data,
                              blog=blog,
                              commentedBy=current_user)
            db.session.add(comment)
            db.session.commit()
            flash('Your comment has been created!', 'success')
        return render_template('blog.html',
                               blog=blog,
                               blog_id=blog_id,
                               comments=blog.comment)

    return render_template('create_comment.html',
                           subject='New Comment',
                           form=form,
                           legend='New Comment',
                           blog_id=blog_id)
Example #5
0
def edit_comment(blog_id, comment_id):
    blog = Blog.query.get_or_404(blog_id)
    comment = Comment.query.get_or_404(comment_id)
    if comment.commentedBy != current_user:
        abort(403)
    form = CommentForm()
    if form.validate_on_submit():
        comment.sentiment = form.sentiment.data
        comment.comment = form.comment.data
        db.session.commit()
        flash('Your comment has been edited!', 'success')
        return render_template('blog.html',
                               blog=blog,
                               blog_id=blog_id,
                               comments=blog.comment)
        # return redirect(url_for('blogs.blog', blog_id=blog.blog_id))
    elif request.method == 'GET':
        form.sentiment.data = comment.sentiment
        form.comment.data = comment.comment
    return render_template('create_comment.html',
                           title='Update Comment',
                           form=form,
                           legend='Update Comment')
Example #6
0
def new_comment(blog_id):
    form = CommentForm()
    if form.validate_on_submit():
        blog = Blog.query.get(int(blog_id))
        comment = Comment(comment=form.comment.data,
                          sentiment=form.sentiment.data,
                          blog=blog,
                          commentedBy=current_user)
        db.session.add(comment)
        db.session.commit()
        flash('Your comment has been created!', 'success')
        print(blog.comment)
        # return redirect(url_for('blogs.blog'), blog=blog, blog_id=blog_id, comments=blog.comment)
        return render_template('blog.html',
                               blog=blog,
                               blog_id=blog_id,
                               comments=blog.comment)

    return render_template('create_comment.html',
                           subject='New Comment',
                           form=form,
                           legend='New Comment',
                           blog_id=blog_id)
Example #7
0
def post(post_id):
    post = Post.query.get_or_404(post_id)
    form = CommentForm()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            comment = Comment(content=form.content.data,
                              author_id=current_user.id,
                              post_id=post.id)
            db.session.add(comment)
            db.session.commit()
            flash('Your comment has been published!', 'success')
            return redirect(url_for('posts.post', post_id=post.id))
        else:
            flash('You need to login to write comments!', 'danger')

    comments_of_post = Comment.query.filter_by(post_id=post.id). \
        order_by(Comment.date_commented.desc()).all()

    return render_template("posts/post.html",
                           title=post.title,
                           post=post,
                           form=form,
                           comments=comments_of_post)
Example #8
0
def new_comment(post_id):
    post = Post.query.get_or_404(post_id)
    user = current_user
    form = CommentForm()
    if form.validate_on_submit():
        if form.picture.data:
            medium = save_picture(form.picture.data)
            comment = Comment(content=form.content.data,
                              commentor=user,
                              post=post,
                              medium=medium)
        else:
            comment = Comment(content=form.content.data,
                              commentor=user,
                              post=post)
        db.session.add(comment)
        db.session.commit()
        flash('Your comment has been submitted!', 'success')
        return redirect(url_for('main.home'))
    return render_template('create_comment.html',
                           title='New Comment',
                           form=form,
                           post=post)