Beispiel #1
0
 def post(self, slug, id):
   form = CommentForm(request.form)
   post = Post.objects.get_or_404(id=id)
   if form.validate():
     comment = Comment(body=form.body.data, author=current_user.id)
     post.comments.append(comment)
     post.save()
   return redirect(post.get_absolute_url())
Beispiel #2
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 #3
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)