Beispiel #1
0
def decorator_from_middleware(middleware_class):
    """
    This is a wrapper around django.utils.decorators.decorator_from_middleware
    (imported as django_decorator_from_middleware). If the middleware class is
    not loaded via MIDDLEWARE_CLASSES in the project settings, then the
    middleware decorator is returned. However, if the middleware is already
    loaded, then an identity decorator is returned instead, so that the
    middleware does not process the view function twice.
    """
    middleware_path = "%s.%s" % (middleware_class.__module__,
                                 middleware_class.__name__)
    if middleware_path in settings.MIDDLEWARE_CLASSES:  # pragma: no cover
        return lambda view_func: view_func
    return django_decorator_from_middleware(middleware_class)
Beispiel #2
0
def decorator_from_middleware(middleware_class):
    """
    This is a wrapper around django.utils.decorators.decorator_from_middleware
    (imported as django_decorator_from_middleware). If the middleware class is
    not loaded via MIDDLEWARE_CLASSES in the project settings, then the
    middleware decorator is returned. However, if the middleware is already
    loaded, then an identity decorator is returned instead, so that the
    middleware does not process the view function twice.
    """
    middleware_path = "%s.%s" % (middleware_class.__module__,
                                 middleware_class.__name__)
    if middleware_path in settings.MIDDLEWARE_CLASSES:
        return lambda view_func: view_func
    return django_decorator_from_middleware(middleware_class)
Beispiel #3
0
# processes a function twice, an ImproperlyConfigured exception is raised.
# Thus, using Django's definition of decorator_from_middleware() can prevent
# reversion integration tests from passing in projects that include
# RevisionMiddleware in MIDDLEWARE_CLASSES.
#
# To avoid this problem, we redefine decorator_from_middleware() to return a
# decorator that does not reapply the middleware if it is in
# MIDDLEWARE_CLASSES.  @decorator_from_middleware(RevisionMiddleware) is then
# used to wrap almost all RevisionMiddleware test views. The only exception is
# double_middleware_revision_view(), which needs to be doubly processed by
# RevisionMiddleware.  This view is wrapped twice with
# @django_decorator_from_middleware(RevisionMiddleware), where
# django_decorator_from_middleware() is imported as Django's definition of
# decorator_from_middleware().

revision_middleware_django_decorator = django_decorator_from_middleware(RevisionMiddleware)

def decorator_from_middleware(middleware_class):
    """
    This is a wrapper around django.utils.decorators.decorator_from_middleware
    (imported as django_decorator_from_middleware). If the middleware class is
    not loaded via MIDDLEWARE_CLASSES in the project settings, then the
    middleware decorator is returned. However, if the middleware is already
    loaded, then an identity decorator is returned instead, so that the
    middleware does not process the view function twice.
    """
    middleware_path = "%s.%s" % (middleware_class.__module__,
                                 middleware_class.__name__)
    if middleware_path in settings.MIDDLEWARE_CLASSES:  # pragma: no cover
        return lambda view_func: view_func
    return django_decorator_from_middleware(middleware_class)
Beispiel #4
0
# processes a function twice, an ImproperlyConfigured exception is raised.
# Thus, using Django's definition of decorator_from_middleware() can prevent
# reversion integration tests from passing in projects that include
# RevisionMiddleware in MIDDLEWARE_CLASSES.
#
# To avoid this problem, we redefine decorator_from_middleware() to return a
# decorator that does not reapply the middleware if it is in
# MIDDLEWARE_CLASSES.  @decorator_from_middleware(RevisionMiddleware) is then
# used to wrap almost all RevisionMiddleware test views. The only exception is
# double_middleware_revision_view(), which needs to be doubly processed by
# RevisionMiddleware.  This view is wrapped twice with
# @django_decorator_from_middleware(RevisionMiddleware), where
# django_decorator_from_middleware() is imported as Django's definition of
# decorator_from_middleware().

revision_middleware_django_decorator = django_decorator_from_middleware(RevisionMiddleware)

def decorator_from_middleware(middleware_class):
    """
    This is a wrapper around django.utils.decorators.decorator_from_middleware
    (imported as django_decorator_from_middleware). If the middleware class is
    not loaded via MIDDLEWARE_CLASSES in the project settings, then the
    middleware decorator is returned. However, if the middleware is already
    loaded, then an identity decorator is returned instead, so that the
    middleware does not process the view function twice.
    """
    middleware_path = "%s.%s" % (middleware_class.__module__,
                                 middleware_class.__name__)
    if middleware_path in settings.MIDDLEWARE_CLASSES:
        return lambda view_func: view_func
    return django_decorator_from_middleware(middleware_class)