Fixed #25610 -- Reverted removal of request.current_app in {% url %} tag.

The deprecation removal in 5e450c52aa
removed too much.
This commit is contained in:
Marten Kenbeek 2015-10-26 14:28:05 +01:00 committed by Tim Graham
parent 23073f9644
commit 34af2bc523
2 changed files with 25 additions and 2 deletions

View File

@ -434,9 +434,12 @@ class URLNode(Node):
} }
view_name = self.view_name.resolve(context) view_name = self.view_name.resolve(context)
try: try:
current_app = context.request.resolver_match.namespace current_app = context.request.current_app
except AttributeError: except AttributeError:
current_app = None try:
current_app = context.request.resolver_match.namespace
except AttributeError:
current_app = None
# Try to look up the URL. If it fails, raise NoReverseMatch unless the # Try to look up the URL. If it fails, raise NoReverseMatch unless the
# {% url ... as var %} construct is used, in which case return nothing. # {% url ... as var %} construct is used, in which case return nothing.
url = '' url = ''

View File

@ -251,3 +251,23 @@ class UrlTagTests(SimpleTestCase):
context = RequestContext(request) context = RequestContext(request)
output = template.render(context) output = template.render(context)
self.assertEqual(output, '/ns2/named-client/42/') self.assertEqual(output, '/ns2/named-client/42/')
@setup({'url-namespace-no-current-app': '{% url "app:named.client" 42 %}'})
def test_url_namespace_no_current_app(self):
request = RequestFactory().get('/')
request.resolver_match = resolve('/ns1/')
request.current_app = None
template = self.engine.get_template('url-namespace-no-current-app')
context = RequestContext(request)
output = template.render(context)
self.assertEqual(output, '/ns2/named-client/42/')
@setup({'url-namespace-explicit-current-app': '{% url "app:named.client" 42 %}'})
def test_url_namespace_explicit_current_app(self):
request = RequestFactory().get('/')
request.resolver_match = resolve('/ns1/')
request.current_app = 'app'
template = self.engine.get_template('url-namespace-explicit-current-app')
context = RequestContext(request)
output = template.render(context)
self.assertEqual(output, '/ns2/named-client/42/')