def check_sites_middleware(app_configs, **kwargs): if middlewares_or_subclasses_installed([SITE_PERMISSION_MIDDLEWARE]): return [Warning(SITE_PERMISSION_MIDDLEWARE + " missing from settings.MIDDLEWARE - per site" " permissions not applied", id="mezzanine.core.W04")] return []
def check_sites_middleware(app_configs, **kwargs): if middlewares_or_subclasses_installed([SITE_PERMISSION_MIDDLEWARE]): return [ Warning(SITE_PERMISSION_MIDDLEWARE + " missing from settings.MIDDLEWARE - per site" " permissions not applied", id="mezzanine.core.W04") ] return []
def cache_installed(): """ Returns ``True`` if a cache backend is configured, and the cache middleware classes or subclasses thereof are present. This will be evaluated once per run, and then cached. """ has_key = bool(getattr(settings, "NEVERCACHE_KEY", "")) return (has_key and settings.CACHES and not settings.TESTING and middlewares_or_subclasses_installed([ "mezzanine.core.middleware.UpdateCacheMiddleware", "mezzanine.core.middleware.FetchFromCacheMiddleware", ]))
def has_site_permission(user): """ Checks if a staff user has staff-level access for the current site. The actual permission lookup occurs in ``SitePermissionMiddleware`` which then marks the request with the ``has_site_permission`` flag, so that we only query the db once per request, so this function serves as the entry point for everything else to check access. We also fall back to an ``is_staff`` check if the middleware is not installed, to ease migration. """ if not middlewares_or_subclasses_installed([SITE_PERMISSION_MIDDLEWARE]): return user.is_staff and user.is_active return getattr(user, "has_site_permission", False)
def has_site_permission(user): """ Checks if a staff user has staff-level access for the current site. The actual permission lookup occurs in ``SitePermissionMiddleware`` which then marks the request with the ``has_site_permission`` flag, so that we only query the db once per request, so this function serves as the entry point for everything else to check access. We also fall back to an ``is_staff`` check if the middleware is not installed, to ease migration. """ if not middlewares_or_subclasses_installed([SITE_PERMISSION_MIDDLEWARE]): return user.is_staff and user.is_active return getattr(user, "has_site_permission", False)
def cache_installed(): """ Returns ``True`` if a cache backend is configured, and the cache middleware classes or subclasses thereof are present. This will be evaluated once per run, and then cached. """ has_key = bool(getattr(settings, "NEVERCACHE_KEY", "")) return (has_key and settings.CACHES and not settings.TESTING and middlewares_or_subclasses_installed([ "mezzanine.core.middleware.UpdateCacheMiddleware", "mezzanine.core.middleware.FetchFromCacheMiddleware", ]))
def installed(cls): """ Used in ``mezzanine.pages.views.page`` to ensure ``PageMiddleware`` or a subclass has been installed. We cache the result on the ``PageMiddleware._installed`` to only run this once. """ try: return cls._installed except AttributeError: name = "mezzanine.pages.middleware.PageMiddleware" installed = middlewares_or_subclasses_installed([name]) setattr(cls, "_installed", installed) return installed
def installed(cls): """ Used in ``mezzanine.pages.views.page`` to ensure ``PageMiddleware`` or a subclass has been installed. We cache the result on the ``PageMiddleware._installed`` to only run this once. """ try: return cls._installed except AttributeError: name = "mezzanine.pages.middleware.PageMiddleware" installed = middlewares_or_subclasses_installed([name]) setattr(cls, "_installed", installed) return installed
def csrf_middleware_installed(): csrf_mw_name = "django.middleware.csrf.CsrfViewMiddleware" return middlewares_or_subclasses_installed([csrf_mw_name])
def csrf_middleware_installed(): csrf_mw_name = "django.middleware.csrf.CsrfViewMiddleware" return middlewares_or_subclasses_installed([csrf_mw_name])