Ticket #66: app_root.diff

File app_root.diff, 2.6 KB (added by jbowtie@…, 9 years ago)

Makes request.app_root available to views

  • django/core/urlresolvers.py

     
    2929        self.callback = callback
    3030        self.default_args = default_args or {}
    3131
    32     def resolve(self, path):
     32    def resolve(self, path, app_root = ''):
    3333        match = self.regex.search(path)
    3434        if match:
    3535            # If there are any named groups, use those as kwargs, ignoring
     
    4444            kwargs.update(self.default_args)
    4545
    4646            try: # Lazily load self.func.
    47                 return self.func, args, kwargs
     47                return self.func, args, kwargs, app_root
    4848            except AttributeError:
    4949                self.func = self.get_callback()
    50             return self.func, args, kwargs
     50            return self.func, args, kwargs, app_root
    5151
    5252    def get_callback(self):
    5353        mod_name, func_name = get_mod_func(self.callback)
     
    6565        self.regex = re.compile(regex)
    6666        self.urlconf_name = urlconf_name
    6767
    68     def resolve(self, path):
     68    def resolve(self, path, app_root=''):
    6969        tried = []
    7070        match = self.regex.search(path)
    7171        if match:
    7272            new_path = path[match.end():]
    7373            for pattern in self.urlconf_module.urlpatterns:
    7474                try:
    75                     sub_match = pattern.resolve(new_path)
     75                    sub_match = pattern.resolve(new_path, app_root + match.group(0))
    7676                except Resolver404, e:
    7777                    tried.extend([(pattern.regex.pattern + '   ' + t) for t in e.args[0]['tried']])
    7878                else:
    7979                    if sub_match:
    80                         return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match[2])
     80                        return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match[2]), sub_match[3]
    8181                    tried.append(pattern.regex.pattern)
    8282            raise Resolver404, {'tried': tried, 'path': new_path}
    8383
  • django/core/handlers/base.py

     
    6161
    6262        resolver = urlresolvers.RegexURLResolver(r'^/', settings.ROOT_URLCONF)
    6363        try:
    64             callback, callback_args, callback_kwargs = resolver.resolve(path)
     64            callback, callback_args, callback_kwargs, app_root = resolver.resolve(path)
     65            request.app_root = app_root
    6566
    6667            # Apply view middleware
    6768            for middleware_method in self._view_middleware:
Back to Top