Beispiel #1
0
def post(post_id):
    """View function for post page"""

    #Form object:'Comment'
    form = CommentForm()
    #form.validator_on_submit() will be true and return the
    #data object to form instance form user enter.
    #when the HTTP request is POST
    if form.validate_on_submit():
        new_comment = Comment(id=str(uuid4()), name=form.name.data)
        new_comment.text = form.text.data
        new_comment.date = datetime.datetime.now()
        new_comment.post_id = post_id
        db.session.add(new_comment)
        db.session.commit()

    post = db.session.query(Post).get_or_404(post_id)
    tags = post.tags
    comments = post.comments.order_by(Comment.date.desc()).all()
    recent, top_tags = sidebar_data()

    return render_template('post.html',
                           post=post,
                           tags=tags,
                           comments=comments,
                           form=form,
                           recent=recent,
                           top_tags=top_tags)
Beispiel #2
0
def FullPost(post_id):
    post = Post.query.get(post_id)
    form = CommentForm()

    if form.validate_on_submit():
        cmnt = Comment(content=form.content.data,
                       mainpost=post,
                       comment_author=current_user)
        db.session.add(cmnt)
        db.session.commit()
        flash(f'Comment Added Successfully', 'success')
        return redirect(url_for('FullPost', post_id=post.id))
    elif (form.is_submitted() and (not form.validate())):
        flash(f'An Error Has Occured Please Review Your Comment', 'danger')

    comments = Comment.query.filter_by(mainpost=post)
    return render_template("Post.html",
                           title=post.title,
                           post=post,
                           render_html=render_html,
                           user=post.author,
                           form=form,
                           form2=None,
                           comments=comments)