def comment_change(request, id): """ Update a comment """ comment = get_object_or_404(Comment.objects, pk=id) if request.user.is_staff or (request.user == comment.user): if request.method == "POST": form = CommentSubmitForm(request.POST, prefix="CommentChangeForm", instance=comment) if form.is_valid(): form.save() request.user.message_set.create(message=_("Your comment has been updated.")) return HttpResponseRedirect(comment.get_absolute_url()) else: form = CommentSubmitForm(prefix="CommentChangeForm", instance=comment) return render_to_response("comments/comment_change.html", { "comment" : comment, "form" : form }, context_instance=RequestContext(request)) else: request.user.message_set.create(message=_("You don't have permission to modify this comment.")) return HttpResponseRedirect(comment.get_absolute_url())
def comment_submit(request, slug): """ Submit a new comment """ post = get_object_or_404(Post.objects, slug=slug) form = CommentSubmitForm(request.POST, prefix="CommentSubmitForm") if form.is_valid(): comment = form.save(commit=False) comment.user = request.user comment.post = post comment.save() request.user.message_set.create(message=_("Your comment has been posted.")) return HttpResponseRedirect(reverse("post_detail", kwargs={"slug": post.slug})) else: return render_to_response("comments/comment_error.html", { "form" : form, "post" : post }, context_instance=RequestContext(request))