Skip to content

Commit

Permalink
Simplified templatetags/request_tag.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixxm committed Aug 5, 2017
1 parent 153b496 commit e8bd2c3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions request/templatetags/request_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ def __init__(self, parser, token):
tokens = token.contents.split()
tag_name = tokens.pop(0)
self.kwargs = {}
self.as_varname = 'user_list'

if not ((len(tokens) == 5) or (len(tokens) == 2) or (len(tokens) == 0)):
if len(tokens) not in (5, 2, 0):
raise template.TemplateSyntaxError('Incorrect amount of arguments in the tag {0!r}'.format(tag_name))

if (len(tokens) == 5) and (tokens[0] == 'in'):
if len(tokens) == 5 and tokens[0] == 'in':
tokens.pop(0) # pop 'in' of tokens
try:
self.kwargs[str(tokens.pop(0))] = int(tokens.pop(0))
Expand All @@ -24,10 +25,8 @@ def __init__(self, parser, token):
else:
self.kwargs['minutes'] = 15

if (len(tokens) == 2 and (tokens[0] == 'as')):
if len(tokens) == 2 and tokens[0] == 'as':
self.as_varname = tokens[1]
else:
self.as_varname = 'user_list'

def render(self, context):
context[self.as_varname] = Request.objects.active_users(**self.kwargs)
Expand Down

0 comments on commit e8bd2c3

Please sign in to comment.