Created
April 2, 2014 05:21
-
-
Save avelino/9928377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AllImagesCheckPermissionForObjectsNode(Node): | |
def __init__(self, obj, name): | |
self.obj = Variable(obj) | |
self.name = name | |
def render(self, context): | |
check_published = True | |
if context['request'].user.is_staff or \ | |
context['request'].user.is_superuser: | |
check_published = False | |
context[self.name] = self.obj.resolve(context).all_images( | |
check_published) | |
return '' | |
@register.tag(name='all_images_check_permission') | |
def all_images_check_permission(parser, token): | |
""" | |
{% all_images_check_permission object as images %} | |
""" | |
try: | |
parans = token.split_contents() | |
except ValueError: | |
raise TemplateSyntaxError( | |
_('tag requires exactly two arguments')) | |
if len(parans) != 4: | |
raise TemplateSyntaxError( | |
_('tag requires exactly three arguments')) | |
if parans[2] != 'as': | |
raise TemplateSyntaxError( | |
_("second argument to tag must be 'as'")) | |
return AllImagesCheckPermissionForObjectsNode(parans[1], parans[3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment