Skip to content

Commit

Permalink
Prefer format and use named blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlton Gibson committed Sep 4, 2014
1 parent 4947303 commit ef1fb3d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rest_framework/templatetags/rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def optional_login(request):
except NoReverseMatch:
return ''

snippet = "<li><a href='%s?next=%s'>Log in</a></li>" % (login_url, escape(request.path))
snippet = "<li><a href='{href}?next={next}'>Log in</a></li>".format(href=login_url, next=escape(request.path))
return snippet


Expand All @@ -53,19 +53,19 @@ def optional_logout(request, user):
try:
logout_url = reverse('rest_framework:logout')
except NoReverseMatch:
return '<li class="navbar-text">{0}</li>'.format(user)
return '<li class="navbar-text">{user}</li>'.format(user=user)

snippet = """<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{0}
{user}
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href='{1}?next={2}'>Log out</a></li>
<li><a href='{href}?next={next}'>Log out</a></li>
</ul>
</li>"""

return snippet.format(user, logout_url, escape(request.path))
return snippet.format(user=user, href=logout_url, next=escape(request.path))


@register.simple_tag
Expand Down

0 comments on commit ef1fb3d

Please sign in to comment.