Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rewrote referral_responses to support 1.3

  • Loading branch information...
commit 1e2a6f19517a91cb838371c4f85288d5b572fceb 1 parent 7deeb9a
@brosner brosner authored
Showing with 25 additions and 5 deletions.
  1. +25 −5 anafero/templatetags/anafero_tags.py
View
30 anafero/templatetags/anafero_tags.py
@@ -21,11 +21,31 @@ def create_referral(context, url, obj=None):
return context
-@register.assignment_tag
-def referral_responses(user):
- return ReferralResponse.objects.filter(
- referral__user=user
- ).order_by("-created_at")
+class ReferralResponsesNode(template.Node):
+
+ def __init__(self, user_var, target_var):
+ self.user_var = user_var
+ self.target_var = target_var
+
+ def render(self, context):
+ user = self.user_var.resolve(context)
+ qs = ReferralResponse.objects.filter(referral__user=user)
+ qs = qs.order_by("-created_at")
+ context[self.target_var] = qs
+ return ""
+
+
+@register.tag
+def referral_responses(parser, token):
+ bits = token.split_contents()
+ tag_name = bits[0]
+ bits = bits[1:]
+ if len(bits) < 2 or bits[-2] != "as":
+ raise template.TemplateSyntaxError(
+ "'%s' tag takes at least 2 arguments and the second last "
+ "argument must be 'as'" % tag_name
+ )
+ return ReferralResponsesNode(parser.compile_filter(bits[0]), bits[2])
@register.filter
Please sign in to comment.
Something went wrong with that request. Please try again.