mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
unicode: Added support for non-ASCII labels for URL patterns.
git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5585 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
9bf4bacf13
commit
fc8bdc1af4
@ -38,6 +38,10 @@ def get_callable(lookup_view, can_fail=False):
|
|||||||
If can_fail is True, lookup_view might be a URL pattern label, so errors
|
If can_fail is True, lookup_view might be a URL pattern label, so errors
|
||||||
during the import fail and the string is returned.
|
during the import fail and the string is returned.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
# Bail out early if lookup_view is not ASCII. This can't be a function.
|
||||||
|
lookup_view = lookup_view.encode('ascii')
|
||||||
|
|
||||||
if not callable(lookup_view):
|
if not callable(lookup_view):
|
||||||
mod_name, func_name = get_mod_func(lookup_view)
|
mod_name, func_name = get_mod_func(lookup_view)
|
||||||
try:
|
try:
|
||||||
@ -46,6 +50,8 @@ def get_callable(lookup_view, can_fail=False):
|
|||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
if not can_fail:
|
if not can_fail:
|
||||||
raise
|
raise
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
pass
|
||||||
return lookup_view
|
return lookup_view
|
||||||
get_callable = memoize(get_callable, _callable_cache)
|
get_callable = memoize(get_callable, _callable_cache)
|
||||||
|
|
||||||
@ -266,7 +272,7 @@ class RegexURLResolver(object):
|
|||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
raise NoReverseMatch
|
raise NoReverseMatch
|
||||||
if lookup_view in self.reverse_dict:
|
if lookup_view in self.reverse_dict:
|
||||||
return ''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]])
|
return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]])
|
||||||
raise NoReverseMatch
|
raise NoReverseMatch
|
||||||
|
|
||||||
def reverse_helper(self, lookup_view, *args, **kwargs):
|
def reverse_helper(self, lookup_view, *args, **kwargs):
|
||||||
|
@ -735,6 +735,7 @@ class Templates(unittest.TestCase):
|
|||||||
'url02' : ('{% url regressiontests.templates.views.client_action client.id, action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),
|
'url02' : ('{% url regressiontests.templates.views.client_action client.id, action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),
|
||||||
'url03' : ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'),
|
'url03' : ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'),
|
||||||
'url04' : ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'),
|
'url04' : ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'),
|
||||||
|
'url05' : (u'{% url метка_оператора 1 %}', {}, '/url_tag/unicode/1/'),
|
||||||
|
|
||||||
# Failures
|
# Failures
|
||||||
'url-fail01' : ('{% url %}', {}, template.TemplateSyntaxError),
|
'url-fail01' : ('{% url %}', {}, template.TemplateSyntaxError),
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# coding: utf-8
|
||||||
from django.conf.urls.defaults import *
|
from django.conf.urls.defaults import *
|
||||||
from regressiontests.templates import views
|
from regressiontests.templates import views
|
||||||
|
|
||||||
@ -8,4 +9,5 @@ urlpatterns = patterns('',
|
|||||||
(r'^client/(\d+)/$', views.client),
|
(r'^client/(\d+)/$', views.client),
|
||||||
(r'^client/(\d+)/(?P<action>[^/]+)/$', views.client_action),
|
(r'^client/(\d+)/(?P<action>[^/]+)/$', views.client_action),
|
||||||
url(r'^named-client/(\d+)/$', views.client, name="named.client"),
|
url(r'^named-client/(\d+)/$', views.client, name="named.client"),
|
||||||
|
url(r'^unicode/(\d+)/$', views.client, name=u"метка_оператора"),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user