Ticket #730: mw-depends.diff

File mw-depends.diff, 3.6 KB (added by Rob Hudson <treborhudson@…>, 7 years ago)

Adding example dependencies and testing dependencies are met during management's validate.

  • django/core/management/validation.py

     
    2828    for (app_name, error) in get_app_errors().items():
    2929        e.add(app_name, error)
    3030
     31    # Check middleware ordering
     32    mw_seen = []
     33    for middleware_path in settings.MIDDLEWARE_CLASSES:
     34        try:
     35            dot = middleware_path.rindex('.')
     36        except ValueError:
     37            continue # not middleware
     38        mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:]
     39        try:
     40            mod = __import__(mw_module, {}, {}, [''])
     41        except ImportError, e:
     42            continue
     43        try:
     44            mw_class = getattr(mod, mw_classname)
     45        except AttributeError:
     46            continue # classname not found
     47        try:
     48            mw_instance = mw_class()
     49        except exceptions.MiddlewareNotUsed:
     50            continue
     51        mw_seen.append(middleware_path)
     52        if hasattr(mw_instance, 'depends') and mw_instance.depends:
     53            for dep in mw_instance.depends:
     54                if dep not in mw_seen:
     55                    e.add(middleware_path, 'Dependency on "%s" not met.  Check to make sure the dependent middleware is included in MIDDLEWARE_CLASSES and is listed above %s.' % (dep, mw_classname))
     56
    3157    for cls in models.get_models(app):
    3258        opts = cls._meta
    3359
  • django/contrib/auth/middleware.py

     
    66        return request._cached_user
    77
    88class AuthenticationMiddleware(object):
     9
     10    depends = ('django.contrib.sessions.middleware.SessionMiddleware',)
     11
    912    def process_request(self, request):
    1013        assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
    1114        request.__class__.user = LazyUser()
  • django/contrib/sessions/middleware.py

     
    99
    1010class SessionMiddleware(object):
    1111
     12    depends = ()
     13
    1214    def process_request(self, request):
    1315        engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
    1416        session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None)
  • django/middleware/common.py

     
    2828          appropriately.
    2929    """
    3030
     31    depends = ()
     32
    3133    def process_request(self, request):
    3234        """
    3335        Check for denied User-Agents and rewrite the URL based on
  • django/middleware/doc.py

     
    55    """
    66    Adds an X-View header to internal HEAD requests -- used by the documentation system.
    77    """
     8
     9    depends = ('django.contrib.auth.middleware.AuthenticationMiddleware',)
     10
    811    def process_view(self, request, view_func, view_args, view_kwargs):
    912        """
    1013        If the request method is HEAD and either the IP is internal or the
Back to Top