def reply_comment(post_id, id): try: comment = Comment.get_by_id(id) except: comment = None try: post = Post.get_by_id(post_id) except: post = None if comment is None or post is None: abort(403) form = CommentForm() if request.method == 'POST': if form.validate_on_submit(): try: reply = Comment.create() form.populate_obj(reply) reply.user = current_user reply.post = post reply.reply = comment reply.save() flash(gettext('Comment succesfully created')) return redirect('%s#comment_%s' % (url_for('show_post', id=post.id), reply.id)) except: flash(gettext('Error while posting the new comment, please retry later'), 'error') else: flash(gettext('Invalid submission, please check the message below'), 'error') return redirect(url_for('show_post', id=post.id)) else: form = CommentForm() tmplt = render_template("blog/post_form.js", comment=comment, form=form, postid=post.id) resp = Response(tmplt, status=200, mimetype='text/javascript') return resp
def show_post(id): try: post = Post.get_by_id(id) except: post = None if post is None: abort(404) if request.method == 'POST': if not current_user.is_authenticated(): abort(401) form = CommentForm() if form.validate_on_submit(): try: comment = Comment.create() form.populate_obj(comment) comment.user = current_user comment.post = post comment.save() flash(gettext('Comment succesfully created')) return redirect('%s#comment_%s' % (url_for('show_article', cat=post.category.slug, post=post.slug), comment.id)) except: flash(gettext('Error while posting the new comment, please retry later'), 'error') else: flash(gettext('Invalid submission, please check the message below'), 'error') else: if not current_user.is_authenticated() or post.comments.count() > 50: form = None else: form = CommentForm() return render_template("blog/post-detail.html", title=gettext('Post | %(title)s', title=post.title), post=post, form=form)