Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_comment(request, pk):
- """Add a new comment."""
- p = request.POST
- if p.has_key("body") and p["body"]:
- author = "Anonymous"
- if p["author"]: author = p["author"]
- if p["email"]: email = p["email"]
- comment = Comment(post=Post.objects.get(pk=pk))
- """Save Comment form"""
- if request.user.is_authenticated():
- cf = CommentForm(initial={'author': "foo", 'email': "foobar@bar.baz"}, instance=comment)
- else:
- cf = CommentForm(p, instance=comment)
- cf.fields["author"].required = False
- comment = cf.save(commit=False)
- """save comment instance"""
- if request.user.is_authenticated():
- comment.author = "foo"
- comment.email = "foobar@bar.baz"
- else:
- comment.author = author
- comment.email = email
- notify = True
- if request.user.username == "ak": notify = False
- comment.save(notify=notify)
- return HttpResponseRedirect(reverse("blog.views.post", args=[pk]))
Add Comment
Please, Sign In to add comment