Django

Code

Changeset 5530

Show
Ignore:
Timestamp:
06/24/07 23:34:34 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4453 -- Allow dots in URL pattern names (although the string in that case is first tried as an import path and only then falls back to being treated as a pattern).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/urlresolvers.py

    r5520 r5530  
    2828    silent_variable_failure = True 
    2929 
    30 def get_callable(lookup_view): 
     30def get_callable(lookup_view, can_fail=False): 
     31    """ 
     32    Convert a string version of a function name to the callable object. 
     33 
     34    If the lookup_view is not an import path, it is assumed to be a URL pattern 
     35    label and the original string is returned. 
     36 
     37    If can_fail is True, lookup_view might be a URL pattern label, so errors 
     38    during the import fail and the string is returned. 
     39    """ 
    3140    if not callable(lookup_view): 
    3241        mod_name, func_name = get_mod_func(lookup_view) 
    33         if func_name != '': 
    34             lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 
     42        try: 
     43            if func_name != '': 
     44                lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 
     45        except (ImportError, AttributeError): 
     46            if not can_fail: 
     47                raise 
    3548    return lookup_view 
    3649get_callable = memoize(get_callable, _callable_cache) 
     
    249262    def reverse(self, lookup_view, *args, **kwargs): 
    250263        try: 
    251             lookup_view = get_callable(lookup_view
     264            lookup_view = get_callable(lookup_view, True
    252265        except (ImportError, AttributeError): 
    253266            raise NoReverseMatch 
  • django/trunk/tests/regressiontests/templates/tests.py

    r5443 r5530  
    726726            'url02' : ('{% url regressiontests.templates.views.client_action client.id, action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'), 
    727727            'url03' : ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'), 
    728             'url04' : ('{% url named-client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'), 
     728            'url04' : ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'), 
    729729 
    730730            # Failures 
  • django/trunk/tests/regressiontests/templates/urls.py

    r4901 r5530  
    88    (r'^client/(\d+)/$', views.client), 
    99    (r'^client/(\d+)/(?P<action>[^/]+)/$', views.client_action), 
    10     url(r'^named-client/(\d+)/$', views.client, name="named-client"), 
     10    url(r'^named-client/(\d+)/$', views.client, name="named.client"), 
    1111)