Skip to content

Instantly share code, notes, and snippets.

@Mark-Shine
Created June 14, 2014 14:19
Show Gist options
  • Save Mark-Shine/6e1846169997097c0785 to your computer and use it in GitHub Desktop.
Save Mark-Shine/6e1846169997097c0785 to your computer and use it in GitHub Desktop.
comments_for
@register.inclusion_tag("generic/includes/comments.html", takes_context=True)
def comments_for(context, obj):
"""
Provides a generic context variable name for the object that
comments are being rendered for.
"""
form = ThreadedCommentForm(context["request"], obj)
try:
context["posted_comment_form"]
except KeyError:
context["posted_comment_form"] = form
context["unposted_comment_form"] = form
context["comment_url"] = reverse("comment")
context["object_for_comments"] = obj
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment