Code

Ticket #4129: 5079-patch_for_url_and_prefix.diff

File 5079-patch_for_url_and_prefix.diff, 2.0 KB (added by Michael Axiak <axiak@…>, 7 years ago)

My crack at a fix for this bug.

Line 
1Index: django/conf/urls/defaults.py
2===================================================================
3--- django/conf/urls/defaults.py        (revision 5079)
4+++ django/conf/urls/defaults.py        (working copy)
5@@ -10,6 +10,9 @@
6 def patterns(prefix, *args):
7     pattern_list = []
8     for t in args:
9+        if len(prefix) > 0 and getattr(t, 'callback_str', False):
10+            t.callback = prefix + '.' + t.callback_str
11+
12         if isinstance(t, (list, tuple)):
13             pattern_list.append(url(prefix=prefix, *t))
14         else:
15Index: django/core/urlresolvers.py
16===================================================================
17--- django/core/urlresolvers.py (revision 5079)
18+++ django/core/urlresolvers.py (working copy)
19@@ -94,13 +94,9 @@
20         # which represents the path to a module and a view function name, or a
21         # callable object (view).
22         self.regex = re.compile(regex)
23-        if callable(callback):
24-            self._callback = callback
25-        else:
26-            self._callback = None
27-            self._callback_str = callback
28         self.default_args = default_args or {}
29         self.name = name
30+        self.callback = callback
31 
32     def resolve(self, path):
33         match = self.regex.search(path)
34@@ -118,6 +114,13 @@
35 
36             return self.callback, args, kwargs
37 
38+    def _set_callback(self, callback):
39+        if callable(callback):
40+            self._callback = callback
41+        else:
42+            self._callback = None
43+            self._callback_str = callback
44+
45     def _get_callback(self):
46         if self._callback is not None:
47             return self._callback
48@@ -129,7 +132,7 @@
49         except AttributeError, e:
50             raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))
51         return self._callback
52-    callback = property(_get_callback)
53+    callback = property(_get_callback, _set_callback)
54 
55     def reverse(self, viewname, *args, **kwargs):
56         mod_name, func_name = get_mod_func(viewname)