Code

Ticket #16573: extract_views_from_urlpatterns_diff.txt

File extract_views_from_urlpatterns_diff.txt, 1.1 KB (added by lopopolo, 3 years ago)

git diff of proposed fix

Line 
1diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
2index 1f57900..28319be 100644
3--- a/django/contrib/admindocs/views.py
4+++ b/django/contrib/admindocs/views.py
5@@ -349,17 +349,17 @@ def extract_views_from_urlpatterns(urlpatterns, base=''):
6     """
7     views = []
8     for p in urlpatterns:
9-        if hasattr(p, 'callback'):
10-            try:
11-                views.append((p.callback, base + p.regex.pattern))
12-            except ViewDoesNotExist:
13-                continue
14-        elif hasattr(p, 'url_patterns'):
15+        if hasattr(p, 'url_patterns'):
16             try:
17                 patterns = p.url_patterns
18             except ImportError:
19                 continue
20             views.extend(extract_views_from_urlpatterns(patterns, base + p.regex.pattern))
21+        elif hasattr(p, 'callback'):
22+            try:
23+                views.append((p.callback, base + p.regex.pattern))
24+            except ViewDoesNotExist:
25+                continue
26         else:
27             raise TypeError(_("%s does not appear to be a urlpattern object") % p)
28     return views