Permalink
Browse files

Added a comment_target tag.

  • Loading branch information...
alex committed Aug 20, 2010
1 parent 7b21939 commit 6747fc22fde8a687085c227d4603f3990dbc475d
Showing with 29 additions and 0 deletions.
  1. +21 −0 dialogos/templatetags/dialogos_tags.py
  2. +8 −0 dialogos/tests.py
@@ -1,4 +1,5 @@
from django import template
+from django.core.urlresolvers import reverse
from django.contrib.contenttypes.models import ContentType
@@ -69,6 +70,17 @@ def render(self, context):
return ""
+class CommentTargetNode(BaseCommentNode):
+ requires_as_var = False
+
+ def render(self, context):
+ obj = self.obj.resolve(context)
+ return reverse("post_comment", kwargs={
+ "content_type_id": ContentType.objects.get_for_model(obj).pk,
+ "object_id": obj.pk
+ })
+
+
@register.tag
def comment_count(parser, token):
"""
@@ -100,3 +112,12 @@ def comment_form(parser, token):
form an auth'd user or not.
"""
return CommentFormNode.handle_token(parser, token)
+
+@register.tag
+def comment_target(parser, token):
+ """
+ Usage:
+
+ {% comment_target obj [as varname] %}
+ """
+ return CommentTargetNode.handle_token(parser, token)
View
@@ -111,3 +111,11 @@ def test_ttag_comment_form(self):
""
)
self.assertTrue(isinstance(c["comment_form"], AuthenticatedCommentForm))
+
+ def test_ttag_comment_target(self):
+ g = User.objects.create(username="legolas")
+ self.assert_renders(
+ "{% load dialogos_tags %}{% comment_target o %}",
+ Context({"o": g}),
+ "/comment/%d/%d/" % (ContentType.objects.get_for_model(g).pk, g.pk)
+ )

0 comments on commit 6747fc2

Please sign in to comment.