def post(self, request, *args, **kwargs): post = self.get_object() if post.closed: messages.error(request, _('This post is closed. Your comment was not added.')) return HttpResponseRedirect(reverse("aristotle:discussionsPost", args=[post.pk])) form = MDRForms.discussions.CommentForm(request.POST) if form.is_valid(): new = MDR.DiscussionComment( post=post, body=form.cleaned_data['body'], author=request.user, ) new.save() return HttpResponseRedirect(reverse("aristotle:discussionsPost", args=[new.post.pk]) + "#comment_%s" % new.id) else: return render(request, "aristotle_mdr/discussions/new.html", {"form": form})
def new_comment(request, pid): post = get_object_or_404(MDR.DiscussionPost, pk=pid) if not perms.user_in_workgroup(request.user, post.workgroup): raise PermissionDenied if post.closed: messages.error(request, _('This post is closed. Your comment was not added.')) return HttpResponseRedirect(reverse("aristotle:discussionsPost", args=[post.pk])) if request.method == 'POST': form = MDRForms.discussions.CommentForm(request.POST) if form.is_valid(): new = MDR.DiscussionComment( post=post, body=form.cleaned_data['body'], author=request.user, ) new.save() return HttpResponseRedirect(reverse("aristotle:discussionsPost", args=[new.post.pk]) + "#comment_%s" % new.id) else: return render(request, "aristotle_mdr/discussions/new.html", {"form": form}) else: # It makes no sense to "GET" this comment, so push them back to the discussion return HttpResponseRedirect(reverse("aristotle:discussionsPost", args=[post.pk]))