def post(request, post): comment_form = forms.CommentForm(request=request) antispam.process_form_init(request, comment_form) comments = Comment.published.filter(post=post)\ .select_related("created_by", "post")\ .order_by("created_on") pingbacks = Pingback.objects.filter( post=post, incoming=True, finished=True, ) return { "post": post, "comments": comments, 'pingbacks': pingbacks, "comment_form": comment_form }
def _do_comment(request, post, defaults={}, comment=None): profile = get_profile(request) if not post.allow_comment_from(profile): return http.HttpResponseRedirect(post.get_absolute_url())#FIXME: add message if comment and profile not in (comment.created_by, post.created_by): return http.HttpResponseRedirect(comment.get_absolute_url()) if request.method == 'POST': form = forms.CommentForm( data=request.POST, request=request, instance=comment ) antispam.process_form_init(request, form) if form.is_valid(): new_comment = form.save(False) if post: new_comment.post = post new_comment.__dict__.update(defaults) if 'view' in request.POST: comment = new_comment else: if not new_comment.created_by.trusted: new_comment.status = post.get_comment_status(new_comment) antispam.process_form_submit( request, form, new_comment, post ) new_comment.save() if new_comment.is_published: if comment: signal = signals.comment_edited else: signal = signals.comment_added signal.send( sender=Comment, comment=new_comment, instance=post ) if new_comment.status == Comment.statuses.spam: new_comment.created_by.message_set.create( message=gettext('Your comment added to moderation queue') ) else: new_comment.subscribe_author(email=False) if comment is None: # send only if created new_comment.emit_event() if form.need_auth_redirect(): return http.HttpResponseRedirect( form.auth_redirect(new_comment.get_absolute_url()) ) if new_comment.status == Comment.statuses.spam: return http.HttpResponseRedirect(post.get_absolute_url() + '#messages') else: return http.HttpResponseRedirect(new_comment.get_absolute_url()) else: form = forms.CommentForm( request=request, instance=comment ) antispam.process_form_init(request, form) return { "comment_form": form, "comment": comment }