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@…>, 8 years ago)

My crack at a fix for this bug.

  • django/conf/urls/defaults.py

     
    1010def patterns(prefix, *args):
    1111    pattern_list = []
    1212    for t in args:
     13        if len(prefix) > 0 and getattr(t, 'callback_str', False):
     14            t.callback = prefix + '.' + t.callback_str
     15
    1316        if isinstance(t, (list, tuple)):
    1417            pattern_list.append(url(prefix=prefix, *t))
    1518        else:
  • django/core/urlresolvers.py

     
    9494        # which represents the path to a module and a view function name, or a
    9595        # callable object (view).
    9696        self.regex = re.compile(regex)
    97         if callable(callback):
    98             self._callback = callback
    99         else:
    100             self._callback = None
    101             self._callback_str = callback
    10297        self.default_args = default_args or {}
    10398        self.name = name
     99        self.callback = callback
    104100
    105101    def resolve(self, path):
    106102        match = self.regex.search(path)
     
    118114
    119115            return self.callback, args, kwargs
    120116
     117    def _set_callback(self, callback):
     118        if callable(callback):
     119            self._callback = callback
     120        else:
     121            self._callback = None
     122            self._callback_str = callback
     123
    121124    def _get_callback(self):
    122125        if self._callback is not None:
    123126            return self._callback
     
    129132        except AttributeError, e:
    130133            raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))
    131134        return self._callback
    132     callback = property(_get_callback)
     135    callback = property(_get_callback, _set_callback)
    133136
    134137    def reverse(self, viewname, *args, **kwargs):
    135138        mod_name, func_name = get_mod_func(viewname)
Back to Top