Ticket #26431: patch-stable-1.9.txt

File patch-stable-1.9.txt, 2.2 KB (added by EugeneM, 9 years ago)
Line 
1diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
2index 141cd14..4e9bd85 100644
3--- a/django/core/urlresolvers.py
4+++ b/django/core/urlresolvers.py
5@@ -686,6 +686,7 @@ def translate_url(url, lang_code):
6 to_be_reversed = "%s:%s" % (match.namespace, match.url_name) if match.namespace else match.url_name
7 with override(lang_code):
8 try:
9+ match.kwargs = dict((k, v) for k, v in match.kwargs.iteritems() if not v is None)
10 url = reverse(to_be_reversed, args=match.args, kwargs=match.kwargs)
11 except NoReverseMatch:
12 pass
13diff --git a/tests/i18n/patterns/tests.py b/tests/i18n/patterns/tests.py
14index 1e8bb9d..485a3c7 100644
15--- a/tests/i18n/patterns/tests.py
16+++ b/tests/i18n/patterns/tests.py
17@@ -138,6 +138,9 @@ class URLTranslationTests(URLTestCaseBase):
18 with translation.override('en'):
19 self.assertEqual(translate_url('/en/non-existent/', 'nl'), '/en/non-existent/')
20 self.assertEqual(translate_url('/en/users/', 'nl'), '/nl/gebruikers/')
21+ # URL with arguments
22+ self.assertEqual(translate_url('/en/with-arguments/regular-argument/', 'nl'), '/nl/with-arguments/regular-argument/')
23+ self.assertEqual(translate_url('/en/with-arguments/regular-argument/optional-argument.html', 'nl'), '/nl/with-arguments/regular-argument/optional-argument.html')
24 # Namespaced URL
25 self.assertEqual(translate_url('/en/account/register/', 'nl'), '/nl/profiel/registeren/')
26 self.assertEqual(translation.get_language(), 'en')
27diff --git a/tests/i18n/patterns/urls/default.py b/tests/i18n/patterns/urls/default.py
28index caf1a76..d35a610 100644
29--- a/tests/i18n/patterns/urls/default.py
30+++ b/tests/i18n/patterns/urls/default.py
31@@ -15,6 +15,7 @@ urlpatterns = [
32 urlpatterns += i18n_patterns(
33 url(r'^prefixed/$', view, name='prefixed'),
34 url(r'^prefixed\.xml$', view, name='prefixed_xml'),
35+ url(r'^with-arguments/(?P<argument>[\w-]+)/(?:(?P<argumentOptional>[\w-]+).html)?$', view, name='with-arguments'),
36 url(_(r'^users/$'), view, name='users'),
37 url(_(r'^account/'), include('i18n.patterns.urls.namespace', namespace='account')),
38 )
Back to Top