Exemple #1
0
def blog(id):
    if id is None:
        abort(404)
    blog = Blog.query.filter_by(id=int(id)).first()
    if blog is None:
        abort(404)
    form = CommentForm()
    if current_user.has_permission(Permission.COMMENT):
        if form.validate_on_submit():
            comment = Comment()
            comment.blog_id = blog.id
            comment.author_id = current_user.id
            comment.body = form.comment.data
            comment.disabled = False
            db.session.add(comment)
            db.session.commit()
            return redirect(url_for('main.blog', id=blog.id))
    # comments = Comment.query.filter_by(blog_id = blog.id).all()
    page = request.args.get('page', type=int, default=1)
    pagination = blog.comments.order_by(Comment.time.desc()).paginate(
        page, 3, False)
    comments = pagination.items
    return render_template('main/blog.html',
                           blog=blog,
                           form=form,
                           comments=comments,
                           pagination=pagination)
Exemple #2
0
def post_comment():
    form = PostComment()
    nid = request.args.get('nid')
    if form.validate_on_submit():
        comment = Comment()
        comment.body = form.body.data
        comment.new_id = nid
        comment.user_id = current_user.id
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for('main.news', nid=nid))
    return render_template('main/post_comment.html', form=form)
def addComment(user_id, topic_id, body):
    """Add a comment to the database and commit the change.
    args:
        user_id: int
        topic_id: int
        body: string
    """
    ## Initialize comment attributes
    comment = Comment()
    comment.user_id = user_id
    comment.topic_id = topic_id
    comment.body = body
    ## add new comment to the database and commit the change
    db.session.add(comment)
    db.session.commit()
    ## Display a message to make sure this works
    flash('Comment created!','info')
Exemple #4
0
def detail_view(request, year, month, date, post):
    post = get_object_or_404(Post,
                             slug=post,
                             status='published',
                             publish__year=year,
                             publish__month=month)
    comments = post.comments.filter(active=True)
    csubmit = False
    if request.method == 'POST':
        list = Comment()
        list.name = request.user
        t = request.user
        list.email = t.email
        list.body = request.POST.get("comment")
        list.post = post
        list.save()
        csubmit = True
    else:
        pass
    return render(request, 'app\detail.html', {
        'list': post,
        'csubmit': csubmit,
        'comments': comments
    })
 def test_markdown(self):
     c = Comment()
     c.body = '# title\n\n## section\n\ntext **bold** and *italic*'
     self.assertTrue(c.body_html == '<h1>title</h1>\n<h2>section</h2>\n'
                     '<p>text <strong>bold</strong> '
                     'and <em>italic</em></p>')
 def test_markdown(self):
     c = Comment()
     c.body = '# title\n\n## section\n\ntext **bold** and *italic*'
     self.assertTrue(c.body_html == '<h1>title</h1>\n<h2>section</h2>\n'
                     '<p>text <strong>bold</strong> '
                     'and <em>italic</em></p>')