Ticket #16406: valueslisterrormessage3.diff

File valueslisterrormessage3.diff, 8.1 KB (added by antoviaque, 4 years ago)
  • django/core/urlresolvers.py

    diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
    index b634b56..2ab0235 100644
    a b def get_mod_func(callback): 
    134134        dot = callback.rindex('.')
    135135    except ValueError:
    136136        return callback, ''
    137     return callback[:dot], callback[dot+1:]
     137    return callback[:dot], callback[dot + 1:]
    138138
    139139class LocaleRegexProvider(object):
    140140    """
    class RegexURLPattern(LocaleRegexProvider): 
    204204            else:
    205205                args = match.groups()
    206206            # In both cases, pass any extra_kwargs as **kwargs.
    207             kwargs.update(self.default_args)
     207            kw = self.default_args.copy()
     208            kw.update(kwargs)
    208209
    209             return ResolverMatch(self.callback, args, kwargs, self.name)
     210            return ResolverMatch(self.callback, args, kw, self.name)
    210211
    211212    @property
    212213    def callback(self):
    class RegexURLResolver(LocaleRegexProvider): 
    368369                    if len(args) != len(params) + len(prefix_args):
    369370                        continue
    370371                    unicode_args = [force_unicode(val) for val in args]
    371                     candidate =  (prefix_norm + result) % dict(zip(prefix_args + params, unicode_args))
     372                    candidate = (prefix_norm + result) % dict(zip(prefix_args + params, unicode_args))
    372373                else:
    373374                    if set(kwargs.keys() + defaults.keys()) != set(params + defaults.keys() + prefix_args):
    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..1a30955 100644
    a b Example requests: 
    110110
    111111.. _Dive Into Python's explanation: http://diveintopython.net/regular_expressions/street_addresses.html#re.matching.2.3
    112112
     113.. _named_groups:
     114
    113115Named groups
    114116============
    115117
    Once you have defined namespaced URLs, you can reverse them. For details on 
    559561reversing namespaced urls, see the documentation on :ref:`reversing namespaced
    560562URLs <topics-http-reversing-url-namespaces>`.
    561563
     564.. _pattern_extra_options:
     565
    562566Passing extra options to view functions
    563567=======================================
    564568
    options to views. 
    587591
    588592    It's possible to have a URL pattern which captures named keyword arguments,
    589593    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
     594    arguments. When this happens, the arguments captured in the URL will be used
     595    instead of the arguments in the dictionary.
     596
     597.. versionadded:: 1.4
     598    Previously, in case of a conflict, the arguments in the dictionary were used
    591599    instead of the arguments captured in the URL.
    592600
     601
    593602Passing extra options to ``include()``
    594603--------------------------------------
    595604
    If the URL does not resolve, the function raises an 
    933942    .. attribute:: ResolverMatch.kwargs
    934943
    935944        The keyword arguments that would be passed to the view
    936         function, as parsed from the URL.
    937 
     945        function, as parsed from the URL or provided to
     946        :func:`~django.core.urlresolvers.pattern`, the keywords
     947        parsed from the URL taking precedence whenever there is
     948        a conflict. See :ref:`pattern_extra_options` and
     949        :ref:`named_groups`.   
     950   
    938951    .. attribute:: ResolverMatch.url_name
    939952
    940953        The name of the URL pattern that matches the URL.
  • 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..6b94cba 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}, name='no-prefix-translated-slug'),
    1313)
    1414
    1515urlpatterns += i18n_patterns('',
  • tests/regressiontests/urlpatterns_reverse/tests.py

    diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
    index a1c9244..8683d60 100644
    a b class ErroneousViewTests(TestCase): 
    511511        self.assertRaises(ViewDoesNotExist, self.client.get, '/missing_outer/')
    512512        self.assertRaises(ViewDoesNotExist, self.client.get, '/uncallable/')
    513513
     514class TestRereverse(TestCase):
     515    urls = 'regressiontests.urlpatterns_reverse.urls'
     516
     517    def test_kwargs_conflict(self):
     518        match = resolve('/rereverse-overridden/12/url/')
     519        self.assertEqual(match.kwargs, {'arg': '12', 'extra': True, 'overridden': 'url'})
     520
     521    def test_rereverse(self):
     522        match = resolve('/rereverse/12/')
     523        self.assertEqual(reverse(match.url_name, args=match.args, kwargs=match.kwargs), '/rereverse/12/')
     524        match = resolve('/rereverse-overridden/12/url/')
     525        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..4a3ff6a 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}, name='rereverse'),
     45    url(r'^rereverse-overridden/(?P<arg>\d+)/(?P<overridden>\w+)/$', empty_view, {'extra': True, 'overridden': 'default'}, name='rereverse-overridden'),
    4446    url(r'^(?P<name>.+)/\d+/$', empty_view, name="mixed"),
    4547    url(r'^repeats/a{1,2}/$', empty_view, name="repeats"),
    4648    url(r'^repeats/a{2,4}/$', empty_view, name="repeats2"),
Back to Top