Beispiel #1
0
def EditComment(comment_id):

    cmnt2 = Comment.query.get(comment_id)
    post = cmnt2.mainpost

    form2 = EditCommentForm()
    if request.method == "GET":
        form2.content.data = cmnt2.content
    elif (form2.submit2.data and form2.validate()):
        cmnt2.content = form2.content.data
        db.session.commit()
        flash(f'Comment Edited Successfully', 'success')
        return redirect(url_for('FullPost', post_id=post.id))

    form = CommentForm()

    if (form.submit.data and form.validate()):
        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,
                           form2=form2,
                           form=form,
                           comments=comments)
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)