Django

Code

Changeset 1470

Show
Ignore:
Timestamp:
11/27/05 16:08:51 (4 years ago)
Author:
adrian
Message:

Fixed #878 -- URLconf regex captures no longer have to be named groups. Old URLconfs (with named groups) still work. This is backwards-incompatible if you've defined custom middleware with a process_view function. See http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/handlers/base.py

    r1356 r1470  
    6363        resolver = urlresolvers.RegexURLResolver(r'^/', ROOT_URLCONF) 
    6464        try: 
    65             callback, param_dict = resolver.resolve(path) 
     65            callback, callback_args, callback_kwargs = resolver.resolve(path) 
    6666 
    6767            # Apply view middleware 
    6868            for middleware_method in self._view_middleware: 
    69                 response = middleware_method(request, callback, param_dict
     69                response = middleware_method(request, callback, callback_args, callback_kwargs
    7070                if response: 
    7171                    return response 
    7272 
    7373            try: 
    74                 response = callback(request, **param_dict
     74                response = callback(request, *callback_args, **callback_kwargs
    7575            except Exception, e: 
    7676                # If the view raised an exception, run it through exception 
  • django/trunk/django/core/urlresolvers.py

    r1376 r1470  
    55a string) and returns a tuple in this format: 
    66 
    7     (view_function, dict_of_view_function_args) 
     7    (view_function, function_args, function_kwargs) 
    88""" 
    99 
     
    3232        match = self.regex.search(path) 
    3333        if match: 
    34             args = dict(match.groupdict(), **self.default_args) 
     34            # If there are any named groups, use those as kwargs, ignoring 
     35            # non-named groups. Otherwise, pass all non-named arguments as 
     36            # positional arguments. 
     37            kwargs = match.groupdict() 
     38            if kwargs: 
     39                args = () 
     40            if not kwargs: 
     41                args = match.groups() 
     42            # In both cases, pass any extra_kwargs as **kwargs. 
     43            kwargs.update(self.default_args) 
     44 
    3545            try: # Lazily load self.func. 
    36                 return self.func, args 
     46                return self.func, args, kwargs 
    3747            except AttributeError: 
    3848                self.func = self.get_callback() 
    39             return self.func, args 
     49            return self.func, args, kwargs 
    4050 
    4151    def get_callback(self): 
     
    6777                else: 
    6878                    if sub_match: 
    69                         return sub_match[0], dict(match.groupdict(), **sub_match[1]) 
     79                        return sub_match[0], sub_match[1], dict(match.groupdict(), **sub_match[2]) 
    7080                    tried.append(pattern.regex.pattern) 
    7181            raise Resolver404, {'tried': tried, 'path': new_path} 
  • django/trunk/django/middleware/doc.py

    r580 r1470  
    66    Adds an X-View header to internal HEAD requests -- used by the documentation system. 
    77    """ 
    8  
    9     def process_view(self, request, view_func, param_dict): 
     8    def process_view(self, request, view_func, view_args, view_kwargs): 
    109        """ 
    1110        If the request method is HEAD and the IP is internal, quickly return 
  • django/trunk/django/utils/decorators.py

    r1076 r1470  
    1414                    return result 
    1515            if hasattr(middleware, 'process_view'): 
    16                 result = middleware.process_view(request, view_func, **kwargs) 
     16                result = middleware.process_view(request, view_func, *args, **kwargs) 
    1717                if result is not None: 
    1818                    return result