예제 #1
0
def comment(post_id):
    post = Post.query.get_or_404(post_id)
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(content=form.content.data,
                          date_posted=datetime.now(timezone('Asia/Kolkata')),
                          user_id=current_user.id,
                          post_id=post_id)
        db.session.add(comment)
        db.session.commit()
        flash('You have added a comment!', 'success')
        return redirect(url_for('post', post_id=post.id))
    return render_template('comment.html',
                           title=post.title,
                           post=post,
                           form=form)
예제 #2
0
파일: routes.py 프로젝트: Protocs/OkayTrack
def view_task(task_id):
    user = User.get_by_username(session["user_name"])
    task = Task.get_task_by_id(task_id, session["user_name"])
    comments = Comment.query.filter_by(task_id=task_id).all()
    form = CommentForm()
    if form.validate_on_submit():
        if user.blocked:
            form.comment.errors.append(
                "Вы заблокированы и не можете оставлять комментарии")
            return render_template("task_view.html",
                                   form=form,
                                   task=task,
                                   comments=comments,
                                   user=user)
        db.session.add(
            Comment(task_id=task_id,
                    username=session["user_name"],
                    comment=form.comment.data))
        db.session.commit()
    return render_template("task_view.html",
                           form=form,
                           task=task,
                           comments=comments,
                           user=user)