From da50848a71e12cac7260e9a529ab15b8b8cd6ed0 Mon Sep 17 00:00:00 2001 From: Christopher Long Date: Sat, 19 Aug 2006 16:26:11 +0000 Subject: [PATCH] [per-object-permissions] Fixed bug in if_has_perm tag that would cause it to not work if an object paramter was not passed to it git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@3614 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/auth/templatetags/auth.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/django/contrib/auth/templatetags/auth.py b/django/contrib/auth/templatetags/auth.py index 5459b5f81a..e40425d64a 100644 --- a/django/contrib/auth/templatetags/auth.py +++ b/django/contrib/auth/templatetags/auth.py @@ -33,11 +33,11 @@ def if_has_perm(parser, token): if tokens[1] is "not": not_flag = True permission=tokens[2] - if tokens[3]: + if len(tokens)>3: object=tokens[3] else: permission=tokens[1] - if tokens[2]: + if len(tokens)>2: object=tokens[2] if not (permission[0] == permission[-1] and permission[0] in ('"', "'")): @@ -69,11 +69,14 @@ class HasPermNode(template.Node): nodes.extend(self.nodelist_false.get_nodes_by_type(nodetype)) return nodes - def render(self, context): - try: - object = template.resolve_variable(self.object_name, context) - except template.VariableDoesNotExist: - return '' + def render(self, context): + if self.object_name: + try: + object = template.resolve_variable(self.object_name, context) + except template.VariableDoesNotExist: + return '' + else: + object=None try: user = template.resolve_variable("user", context) @@ -86,5 +89,6 @@ class HasPermNode(template.Node): return self.nodelist_true.render(context) if (self.not_flag and bool_perm) or (not self.not_flag and not bool_perm): return self.nodelist_false.render(context) + return '' register.tag('if_has_perm', if_has_perm) \ No newline at end of file