Ticket #16406: t16406_new.diff

File t16406_new.diff, 6.5 KB (added by Florian Apolloner, 13 years ago)
  • django/core/urlresolvers.py

    diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
    index b634b56..e31d4fa 100644
    a b class RegexURLPattern(LocaleRegexProvider):  
    198198            # If there are any named groups, use those as kwargs, ignoring
    199199            # non-named groups. Otherwise, pass all non-named arguments as
    200200            # positional arguments.
    201             kwargs = match.groupdict()
    202             if kwargs:
     201            match_kwargs = match.groupdict()
     202            if match_kwargs:
    203203                args = ()
    204204            else:
    205205                args = match.groups()
    206206            # In both cases, pass any extra_kwargs as **kwargs.
    207             kwargs.update(self.default_args)
     207            kwargs = self.default_args.copy()
     208            kwargs.update(match_kwargs)
    208209
    209210            return ResolverMatch(self.callback, args, kwargs, self.name)
    210211
    class RegexURLResolver(LocaleRegexProvider):  
    374375                        continue
    375376                    matches = True
    376377                    for k, v in defaults.items():
     378                        if k in params:
     379                            continue
    377380                        if kwargs.get(k, v) != v:
    378381                            matches = False
    379382                            break
  • docs/topics/http/urls.txt

    diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt
    index f3e27ae..02d9ac9 100644
    a b options to views.  
    587587
    588588    It's possible to have a URL pattern which captures named keyword arguments,
    589589    and also passes arguments with the same names in its dictionary of extra
    590     arguments. When this happens, the arguments in the dictionary will be used
    591     instead of the arguments captured in the URL.
     590    arguments. When this happens, the arguments captured in the url will be
     591    used instead of the arguments in the dictionary.
    592592
    593593Passing extra options to ``include()``
    594594--------------------------------------
  • tests/regressiontests/i18n/patterns/tests.py

    diff --git a/tests/regressiontests/i18n/patterns/tests.py b/tests/regressiontests/i18n/patterns/tests.py
    index 1cc4520..5a8e868 100644
    a b import os  
    44import warnings
    55
    66from django.core.exceptions import ImproperlyConfigured
    7 from django.core.urlresolvers import reverse, clear_url_caches
     7from django.core.urlresolvers import reverse, resolve, clear_url_caches
    88from django.test import TestCase
    99from django.test.utils import override_settings
    1010from django.template import Template, Context
    class URLTagTests(URLTestCaseBase):  
    306306            {% language 'pt-br' %}{% url 'no-prefix-translated-slug' slug='apo' %}{% endlanguage %}""")
    307307        self.assertEqual(tpl.render(Context({})).strip().split(),
    308308                         [u'/vertaald/apo/', u'/traduzidos/apo/'])
     309
     310
     311class URLExampleTests(URLTestCaseBase):
     312    def test_demo(self):
     313        # User accesses an english url.
     314        with translation.override('en'):
     315            match = resolve('/translated/apo/')
     316        # Now we want provide links to the same page in other languages
     317        links = []
     318        langs = ['nl', 'pt-br']
     319        for lang in langs:
     320            with translation.override(lang):
     321                links.append(reverse(match.url_name, args=match.args, kwargs=match.match_kwargs))
     322        self.assertEqual(links, [u'/vertaald/apo/', u'/traduzidos/apo/'])
     323        # Now we can offer the user links to the other pages
     324        # print "View the page in: ",
     325        # for lang, link in zip(langs, links):
     326        #   print "<a href='%s'>%s</a> % (link, lang),
  • tests/regressiontests/i18n/patterns/urls/default.py

    diff --git a/tests/regressiontests/i18n/patterns/urls/default.py b/tests/regressiontests/i18n/patterns/urls/default.py
    index f117502..aac68ff 100644
    a b view = TemplateView.as_view(template_name='dummy.html')  
    99urlpatterns = patterns('',
    1010    url(r'^not-prefixed/$', view, name='not-prefixed'),
    1111    url(_(r'^translated/$'), view, name='no-prefix-translated'),
    12     url(_(r'^translated/(?P<slug>[\w-]+)/$'), view, name='no-prefix-translated-slug'),
     12    url(_(r'^translated/(?P<slug>[\w-]+)/$'), view, {'extra': True},
     13        name='no-prefix-translated-slug'),
    1314)
    1415
    1516urlpatterns += i18n_patterns('',
    1617    url(r'^prefixed/$', view, name='prefixed'),
    1718    url(_(r'^users/$'), view, name='users'),
    18     url(_(r'^account/'), include('regressiontests.i18n.patterns.urls.namespace', namespace='account')),
     19    url(_(r'^account/'), include('regressiontests.i18n.patterns.urls.namespace',
     20        namespace='account')),
    1921)
  • tests/regressiontests/urlpatterns_reverse/tests.py

    diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
    index a1c9244..f3c40b9 100644
    a b class ErroneousViewTests(TestCase):  
    511511        self.assertRaises(ViewDoesNotExist, self.client.get, '/missing_outer/')
    512512        self.assertRaises(ViewDoesNotExist, self.client.get, '/uncallable/')
    513513
     514
     515class TestRereverse(TestCase):
     516    urls = 'regressiontests.urlpatterns_reverse.urls'
     517
     518    def test_rereverse(self):
     519        match = resolve('/rereverse/12/')
     520        self.assertEqual(reverse(match.url_name, args=match.args, kwargs=match.kwargs), '/rereverse/12/')
     521        match = resolve('/rereverse-overridden/12/url/')
     522        self.assertEqual(reverse(match.url_name, args=match.args, kwargs=match.kwargs), '/rereverse-overridden/12/url/')
  • tests/regressiontests/urlpatterns_reverse/urls.py

    diff --git a/tests/regressiontests/urlpatterns_reverse/urls.py b/tests/regressiontests/urlpatterns_reverse/urls.py
    index 1d4ae73..fee6546 100644
    a b urlpatterns = patterns('',  
    4141    url(r'^windows_path/(?P<drive_name>[A-Z]):\\(?P<path>.+)/$', empty_view,
    4242            name="windows"),
    4343    url(r'^special_chars/(.+)/$', empty_view, name="special"),
     44    url(r'^rereverse/(?P<arg>\d+)/$', empty_view, {'extra': True},
     45        name='rereverse'),
     46    url(r'^rereverse-overridden/(?P<arg>\d+)/(?P<overridden>\w+)/$',
     47        empty_view, {'extra': True, 'overridden': 'default'},
     48        name='rereverse-overridden'),
    4449    url(r'^(?P<name>.+)/\d+/$', empty_view, name="mixed"),
    4550    url(r'^repeats/a{1,2}/$', empty_view, name="repeats"),
    4651    url(r'^repeats/a{2,4}/$', empty_view, name="repeats2"),
Back to Top