Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Corrected [13479], accounting for unnamed urls that are instances of …

…classes.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13497 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 69d1e71fad3046792f737b26c7da75e8f373eb44 1 parent 75ac6c2
Russell Keith-Magee authored
7  django/core/urlresolvers.py
@@ -41,7 +41,12 @@ def __init__(self, func, args, kwargs, url_name=None, app_name=None, namespaces=
41 41
         else:
42 42
             self.namespaces = []
43 43
         if not url_name:
44  
-            url_name = '.'.join([ func.__module__, func.__name__ ])
  44
+            if not hasattr(func, '__name__'):
  45
+                # An instance of a callable class
  46
+                url_name = '.'.join([func.__class__.__module__, func.__class__.__name__])
  47
+            else:
  48
+                # A function
  49
+                url_name = '.'.join([func.__module__, func.__name__])
45 50
         self.url_name = url_name
46 51
 
47 52
     def namespace(self):
3  tests/regressiontests/urlpatterns_reverse/included_namespace_urls.py
... ...
@@ -1,5 +1,6 @@
1 1
 from django.conf.urls.defaults import *
2 2
 from namespace_urls import URLObject
  3
+from views import view_class_instance
3 4
 
4 5
 testobj3 = URLObject('testapp', 'test-ns3')
5 6
 
@@ -10,6 +11,8 @@
10 11
     url(r'^mixed_args/(\d+)/(?P<arg2>\d+)/$', 'empty_view', name='inc-mixed-args'),
11 12
     url(r'^no_kwargs/(\d+)/(\d+)/$', 'empty_view', name='inc-no-kwargs'),
12 13
 
  14
+    url(r'^view_class/(?P<arg1>\d+)/(?P<arg2>\d+)/$', view_class_instance, name='inc-view-class'),
  15
+
13 16
     (r'^test3/', include(testobj3.urls)),
14 17
     (r'^ns-included3/', include('regressiontests.urlpatterns_reverse.included_urls', namespace='inc-ns3')),
15 18
     (r'^ns-included4/', include('regressiontests.urlpatterns_reverse.namespace_urls', namespace='inc-ns4')),
6  tests/regressiontests/urlpatterns_reverse/namespace_urls.py
... ...
@@ -1,4 +1,5 @@
1 1
 from django.conf.urls.defaults import *
  2
+from views import view_class_instance
2 3
 
3 4
 class URLObject(object):
4 5
     def __init__(self, app_name, namespace):
@@ -26,6 +27,11 @@ def urls(self):
26 27
     url(r'^mixed_args/(\d+)/(?P<arg2>\d+)/$', 'empty_view', name='mixed-args'),
27 28
     url(r'^no_kwargs/(\d+)/(\d+)/$', 'empty_view', name='no-kwargs'),
28 29
 
  30
+    url(r'^view_class/(?P<arg1>\d+)/(?P<arg2>\d+)/$', view_class_instance, name='view-class'),
  31
+
  32
+    (r'^unnamed/normal/(?P<arg1>\d+)/(?P<arg2>\d+)/$', 'empty_view'),
  33
+    (r'^unnamed/view_class/(?P<arg1>\d+)/(?P<arg2>\d+)/$', view_class_instance),
  34
+
29 35
     (r'^test1/', include(testobj1.urls)),
30 36
     (r'^test2/', include(testobj2.urls)),
31 37
     (r'^default/', include(default_testobj.urls)),
6  tests/regressiontests/urlpatterns_reverse/tests.py
@@ -32,12 +32,18 @@
32 32
     # These entries are in the format: (path, url_name, app_name, namespace, view_func, args, kwargs)
33 33
     # Simple case
34 34
     ('/normal/42/37/', 'normal-view', None, '', views.empty_view, tuple(), {'arg1': '42', 'arg2': '37'}),
  35
+    ('/view_class/42/37/', 'view-class', None, '', views.view_class_instance, tuple(), {'arg1': '42', 'arg2': '37'}),
35 36
     ('/included/normal/42/37/', 'inc-normal-view', None, '', views.empty_view, tuple(), {'arg1': '42', 'arg2': '37'}),
  37
+    ('/included/view_class/42/37/', 'inc-view-class', None, '', views.view_class_instance, tuple(), {'arg1': '42', 'arg2': '37'}),
36 38
 
37 39
     # Unnamed args are dropped if you have *any* kwargs in a pattern
38 40
     ('/mixed_args/42/37/', 'mixed-args', None, '', views.empty_view, tuple(), {'arg2': '37'}),
39 41
     ('/included/mixed_args/42/37/', 'inc-mixed-args', None, '', views.empty_view, tuple(), {'arg2': '37'}),
40 42
 
  43
+    # Unnamed views will be resolved to the function/class name
  44
+    ('/unnamed/normal/42/37/', 'regressiontests.urlpatterns_reverse.views.empty_view', None, '', views.empty_view, tuple(), {'arg1': '42', 'arg2': '37'}),
  45
+    ('/unnamed/view_class/42/37/', 'regressiontests.urlpatterns_reverse.views.ViewClass', None, '', views.view_class_instance, tuple(), {'arg1': '42', 'arg2': '37'}),
  46
+
41 47
     # If you have no kwargs, you get an args list.
42 48
     ('/no_kwargs/42/37/', 'no-kwargs', None, '', views.empty_view, ('42','37'), {}),
43 49
     ('/included/no_kwargs/42/37/', 'inc-no-kwargs', None, '', views.empty_view, ('42','37'), {}),
6  tests/regressiontests/urlpatterns_reverse/views.py
@@ -6,3 +6,9 @@ def kwargs_view(request, arg1=1, arg2=2):
6 6
 
7 7
 def absolute_kwargs_view(request, arg1=1, arg2=2):
8 8
     pass
  9
+
  10
+class ViewClass(object):
  11
+    def __call__(self, request, *args, **kwargs):
  12
+        pass
  13
+
  14
+view_class_instance = ViewClass()

0 notes on commit 69d1e71

Please sign in to comment.
Something went wrong with that request. Please try again.