Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed another case of reverse URL resolving that wasn't working.

This is a similar situation to that fixed in r9087. We weren't merging
multiple levels of include() calls together correctly.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9099 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 37ee86b7ee63e057db0a5b868be7f799d8a4d40e 1 parent ba59295
Malcolm Tredinnick malcolmt authored
12 django/core/urlresolvers.py
View
@@ -158,12 +158,12 @@ def _get_reverse_dict(self):
p_pattern = p_pattern[1:]
if isinstance(pattern, RegexURLResolver):
parent = normalize(pattern.regex.pattern)
- for name, (matches, pat) in pattern.reverse_dict.iteritems():
- new_matches = []
- for piece, p_args in parent:
- new_matches.extend([(piece + suffix, p_args + args)
- for (suffix, args) in matches])
- self._reverse_dict.appendlist(name, (new_matches, p_pattern + pat))
+ for name in pattern.reverse_dict:
+ for matches, pat in pattern.reverse_dict.getlist(name):
+ new_matches = []
+ for piece, p_args in parent:
+ new_matches.extend([(piece + suffix, p_args + args) for (suffix, args) in matches])
+ self._reverse_dict.appendlist(name, (new_matches, p_pattern + pat))
else:
bits = normalize(p_pattern)
self._reverse_dict.appendlist(pattern.callback, (bits, p_pattern))
2  tests/regressiontests/urlpatterns_reverse/extra_urls.py
View
@@ -8,4 +8,6 @@
urlpatterns = patterns('',
url(r'^e-places/(\d+)/$', empty_view, name='extra-places'),
url(r'^e-people/(?P<name>\w+)/$', empty_view, name="extra-people"),
+ url('', include('regressiontests.urlpatterns_reverse.included_urls2')),
+ url(r'^prefix/(?P<prefix>\w+)/', include('regressiontests.urlpatterns_reverse.included_urls2')),
)
14 tests/regressiontests/urlpatterns_reverse/included_urls2.py
View
@@ -0,0 +1,14 @@
+"""
+These URL patterns are included in two different ways in the main urls.py, with
+an extra argument present in one case. Thus, there are two different ways for
+each name to resolve and Django must distinguish the possibilities based on the
+argument list.
+"""
+
+from django.conf.urls.defaults import *
+from views import empty_view
+
+urlpatterns = patterns('',
+ url(r'^part/(?P<value>\w+)/$', empty_view, name="part"),
+ url(r'^part2/(?:(?P<value>\w+)/)?$', empty_view, name="part2"),
+)
6 tests/regressiontests/urlpatterns_reverse/tests.py
View
@@ -65,6 +65,12 @@
('extra-places', '/e-places/10/', ['10'], {}),
('extra-people', '/e-people/fred/', ['fred'], {}),
('extra-people', '/e-people/fred/', [], {'name': 'fred'}),
+ ('part', '/part/one/', [], {'value': 'one'}),
+ ('part', '/prefix/xx/part/one/', [], {'value': 'one', 'prefix': 'xx'}),
+ ('part2', '/part2/one/', [], {'value': 'one'}),
+ ('part2', '/part2/', [], {}),
+ ('part2', '/prefix/xx/part2/one/', [], {'value': 'one', 'prefix': 'xx'}),
+ ('part2', '/prefix/xx/part2/', [], {'prefix': 'xx'}),
# Regression for #9038
# These views are resolved by method name. Each method is deployed twice -
Please sign in to comment.
Something went wrong with that request. Please try again.