diff options
| author | Christopher Long <indirecthit@gmail.com> | 2006-08-19 16:26:11 +0000 |
|---|---|---|
| committer | Christopher Long <indirecthit@gmail.com> | 2006-08-19 16:26:11 +0000 |
| commit | da50848a71e12cac7260e9a529ab15b8b8cd6ed0 (patch) | |
| tree | 639f19904b64cfab7ee27d7f1d5881f7eea5a543 | |
| parent | f180bb6ab3181eab8096188e39871c15e908550a (diff) | |
[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
| -rw-r--r-- | django/contrib/auth/templatetags/auth.py | 18 |
1 files 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 |
