Exemple #1
0
def post_comment():

    form = CommentForm()

    pid = 1
    source = 'my'

    if form.validate_on_submit():
        pid = form.pid.data
        p = Project.query.filter_by(id=pid).first_or_404()
        source = form.source.data

        c = Comment()
        c.project = p
        c.author_id = user_manager.current_user.get_id()
        c.content = form.content.data
        # c.timestamp = time.time()

        with safe_session(db):
            db.session.add(c)

    url = 'investor.show_project'

    if source == 'my':
        url = 'investor.project_list_mine_detail'

    return redirect(url_for(url, pid=pid))
Exemple #2
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)