Prefer format and use named blocks

This commit is contained in:
Carlton Gibson 2014-09-04 08:54:50 +02:00
parent 4947303f20
commit ef1fb3d8df

View File

@ -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
@ -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