X-Git-Url: https://git.mdrn.pl/fnpdjango.git/blobdiff_plain/6b8969ee2970107bb5931424501c8c0f567a4488..11218c30e676382183cd6713cb0c3d5af5194e38:/project_name/settings.d/40-middleware.py diff --git a/project_name/settings.d/40-middleware.py b/project_name/settings.d/40-middleware.py index ca43d26..b211d42 100644 --- a/project_name/settings.d/40-middleware.py +++ b/project_name/settings.d/40-middleware.py @@ -1,31 +1,22 @@ -MIDDLEWARE_CLASSES = ( - 'django.contrib.sessions.middleware.SessionMiddleware', +MIDDLEWARE_CLASSES = tuple(x for x in ( + 'django.contrib.sessions.middleware.SessionMiddleware' + if "django.contrib.sessions" in INSTALLED_APPS else None, #'django.middleware.locale.LocaleMiddleware', 'fnpdjango.middleware.URLLocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', -) - -if 'django_cas' in INSTALLED_APPS: - MIDDLEWARE_CLASSES += ( - 'django_cas.middleware.CASMiddleware', - ) - -MIDDLEWARE_CLASSES += ( - 'django.contrib.messages.middleware.MessageMiddleware', -) - -if 'piwik.django' in INSTALLED_APPS: - MIDDLEWARE_CLASSES += ( - 'piwik.django.middleware.PiwikMiddleware', - ) - -MIDDLEWARE_CLASSES += ( + 'django.contrib.auth.middleware.AuthenticationMiddleware' + if "django.contrib.auth" in INSTALLED_APPS else None, + 'django_cas.middleware.CASMiddleware' + if "django_cas" in INSTALLED_APPS else None, + 'django.contrib.messages.middleware.MessageMiddleware' + if "django.contrib.messages" in INSTALLED_APPS else None, + 'piwik.django.middleware.PiwikMiddleware' + if "piwik.django" in INSTALLED_APPS else None, # Uncomment the next line for simple clickjacking protection: # 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'pagination.middleware.PaginationMiddleware', - # Comment out if not behind proxy setting the Real-IP header (like Nginx). - 'fnpdjango.middleware.SetRemoteAddrFromXRealIP', -) + 'pagination.middleware.PaginationMiddleware' + if "pagination" in INSTALLED_APPS else None, + 'fnpdjango.middleware.SetRemoteAddrFromXRealIP' +) if x is not None)