Ticket #730: middleware_ordering_with_path-weight_tuples.diff
File middleware_ordering_with_path-weight_tuples.diff, 2.2 KB (added by , 16 years ago) |
---|
-
django/core/handlers/base.py
29 29 self._view_middleware = [] 30 30 self._response_middleware = [] 31 31 self._exception_middleware = [] 32 for middleware_path in settings.MIDDLEWARE_CLASSES: 32 # (middleware_path, weight) tuples in MIDDLEWARE_CLASSES 33 # heavier items processed first 34 middleware_list = [] 35 for middleware in settings.MIDDLEWARE_CLASSES: 36 middleware_path = middleware[0] 33 37 try: 34 38 dot = middleware_path.rindex('.') 35 39 except ValueError: … … 48 52 mw_instance = mw_class() 49 53 except exceptions.MiddlewareNotUsed: 50 54 continue 55 middleware_list.append((middleware[1], mw_instance)) 51 56 52 if hasattr(mw_instance, 'process_request'): 57 # inbound 58 for middleware in middleware_list: 59 if hasattr(middleware[1], 'process_request'): 53 60 self._request_middleware.append(mw_instance.process_request) 54 if hasattr(m w_instance, 'process_view'):61 if hasattr(middleware[1], 'process_view'): 55 62 self._view_middleware.append(mw_instance.process_view) 56 if hasattr(mw_instance, 'process_response'):57 self._response_middleware.insert(0, mw_instance.process_response)58 if hasattr(mw_instance, 'process_exception'):59 self._exception_middleware.insert(0, mw_instance.process_exception)60 63 64 # outbound 65 middleware_list.sort() 66 middleware_list.reverse() # remove if lighter items first 67 for middleware in middleware_list: 68 if hasattr(middleware[1], 'process_response'): 69 self._response_middleware.append(0, mw_instance.process_response) 70 if hasattr(middleware[1], 'process_exception'): 71 self._exception_middleware.append(0, mw_instance.process_exception) 72 61 73 def get_response(self, request): 62 74 "Returns an HttpResponse object for the given HttpRequest" 63 75 from django.core import exceptions, urlresolvers