"""
Django settings for example project.

Generated by Cookiecutter Django Package
"""

import os
import re

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

# django-sso-app
from django_sso_app.settings import *

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "<KEY>

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'django.contrib.sites',

    'rest_framework',
    'rest_framework.authtoken',

    'django_sso_app',

    'django_uploads_app',

    'tests',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',

    'django_countries',
    'django_filters',

    'treebeard',

    'easy_thumbnails',
    'filer',
    'mptt',

    "django_json_widget",

    # if your app has other dependencies that need to be added to the site
    # they should be added here
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',

    'django.middleware.locale.LocaleMiddleware',

    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',

    'django.contrib.auth.middleware.AuthenticationMiddleware',  # required by django-sso-app
    'django_sso_app.core.authentication.middleware.DjangoSsoAppAuthenticationMiddleware',  # django-sso-app

    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'tests.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
        'OPTIONS': {
            "loaders": [
                "django.template.loaders.filesystem.Loader",
                "django.template.loaders.app_directories.Loader",
            ],
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'tests.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# file root
_ENV_PUBLIC_ROOT = env('DJANGO_PUBLIC_ROOT', default=None)
if _ENV_PUBLIC_ROOT is None:
    PUBLIC_ROOT = os.path.join(BASE_DIR, "public")
else:
    PUBLIC_ROOT = _ENV_PUBLIC_ROOT

_ENV_PRIVATE_ROOT = env('DJANGO_PRIVATE_ROOT', default=None)
if _ENV_PRIVATE_ROOT is None:
    PRIVATE_ROOT = os.path.join(BASE_DIR, "private")
else:
    PRIVATE_ROOT = _ENV_PRIVATE_ROOT

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PUBLIC_ROOT, 'static')

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(PUBLIC_ROOT, 'media')

AUTH_USER_MODEL = 'tests.User'

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
] + DJANGO_SSO_APP_DJANGO_AUTHENTICATION_BACKENDS

DRF_DEFAULT_AUTHENTICATION_CLASSES = [
    'django_sso_app.core.api.authentication.DjangoSsoApiAuthentication',
    'rest_framework.authentication.TokenAuthentication',
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': DRF_DEFAULT_AUTHENTICATION_CLASSES,
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
    'PAGE_SIZE': 100,

    'DATETIME_FORMAT': '%Y-%m-%dT%H:%M:%S%z',

    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ),
}

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/'

SITE_ID = 1

EMAIL_BACKEND = env(
    'DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.console.EmailBackend'
)


# file uploads
FILE_UPLOAD_PERMISSIONS = 0o644
FILE_UPLOAD_HANDLERS = [
    'django.core.files.uploadhandler.TemporaryFileUploadHandler',
]


# django-uploads
DJANGO_UPLOADS_FTP_QUOTA_MB = env.int('DJANGO_UPLOADS_FTP_QUOTA_MB', default=1024)
DJANGO_UPLOADS_NGINX_X_ACCEL_REDIRECT = env.bool('DJANGO_UPLOADS_NGINX_X_ACCEL_REDIRECT', default=not DEBUG)

# django
DEFAULT_FILE_STORAGE = 'django_uploads_app.storage.PrivateFileSystemStorage'  # !!
IGNORABLE_404_URLS = [re.compile(r'/filer_private_thumbnails/*')]  # ignore filer thumbnail generation errors

# django-filer
FILER_STORAGES = {
    'private': {
        'main': {
            'ENGINE': 'django_uploads_app.storage.PrivateFileSystemStorage',
            #'ENGINE': 'filer.storage.PrivateFileSystemStorage',
            'OPTIONS': {
                'location': os.path.abspath(os.path.join(MEDIA_ROOT, '../../private/')),
                'base_url': '/filer_private/',
            },
            'UPLOAD_TO': 'django_uploads_app.utils.generate_filer_filename',
            'UPLOAD_TO_PREFIX': '',
        },
        'thumbnails': {
            'ENGINE': 'django_uploads_app.storage.PrivateFileSystemStorage',
            'OPTIONS': {
                'location': os.path.abspath(os.path.join(MEDIA_ROOT, '../../filer-private/')),
                'base_url': '/filer_private_thumbnails/',
            },
        },
    }
}

FILER_ENABLE_PERMISSIONS = True
FILER_IS_PUBLIC_DEFAULT = False
FILER_DUMP_PAYLOAD = True
FILER_DEBUG = DEBUG
# save payload on dumpdata
FILER_DUMP_PAYLOAD = env.bool('FILER_DUMP_PAYLOAD', default=False)

"""
Django settings for example project.

Generated by Cookiecutter Django Package
"""

import os
import re

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

# django-sso-app
from django_sso_app.settings import *

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "<KEY>

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'django.contrib.sites',

    'rest_framework',
    'rest_framework.authtoken',

    'django_sso_app',

    'django_uploads_app',

    'tests',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',

    'django_countries',
    'django_filters',

    'treebeard',

    'easy_thumbnails',
    'filer',
    'mptt',

    "django_json_widget",

    # if your app has other dependencies that need to be added to the site
    # they should be added here
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',

    'django.middleware.locale.LocaleMiddleware',

    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',

    'django.contrib.auth.middleware.AuthenticationMiddleware',  # required by django-sso-app
    'django_sso_app.core.authentication.middleware.DjangoSsoAppAuthenticationMiddleware',  # django-sso-app

    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'tests.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
        'OPTIONS': {
            "loaders": [
                "django.template.loaders.filesystem.Loader",
                "django.template.loaders.app_directories.Loader",
            ],
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'tests.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# file root
_ENV_PUBLIC_ROOT = env('DJANGO_PUBLIC_ROOT', default=None)
if _ENV_PUBLIC_ROOT is None:
    PUBLIC_ROOT = os.path.join(BASE_DIR, "public")
else:
    PUBLIC_ROOT = _ENV_PUBLIC_ROOT

_ENV_PRIVATE_ROOT = env('DJANGO_PRIVATE_ROOT', default=None)
if _ENV_PRIVATE_ROOT is None:
    PRIVATE_ROOT = os.path.join(BASE_DIR, "private")
else:
    PRIVATE_ROOT = _ENV_PRIVATE_ROOT

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PUBLIC_ROOT, 'static')

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(PUBLIC_ROOT, 'media')

AUTH_USER_MODEL = 'tests.User'

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
] + DJANGO_SSO_APP_DJANGO_AUTHENTICATION_BACKENDS

DRF_DEFAULT_AUTHENTICATION_CLASSES = [
    'django_sso_app.core.api.authentication.DjangoSsoApiAuthentication',
    'rest_framework.authentication.TokenAuthentication',
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': DRF_DEFAULT_AUTHENTICATION_CLASSES,
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
    'PAGE_SIZE': 100,

    'DATETIME_FORMAT': '%Y-%m-%dT%H:%M:%S%z',

    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ),
}

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/'

SITE_ID = 1

EMAIL_BACKEND = env(
    'DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.console.EmailBackend'
)


# file uploads
FILE_UPLOAD_PERMISSIONS = 0o644
FILE_UPLOAD_HANDLERS = [
    'django.core.files.uploadhandler.TemporaryFileUploadHandler',
]


# django-uploads
DJANGO_UPLOADS_FTP_QUOTA_MB = env.int('DJANGO_UPLOADS_FTP_QUOTA_MB', default=1024)
DJANGO_UPLOADS_NGINX_X_ACCEL_REDIRECT = env.bool('DJANGO_UPLOADS_NGINX_X_ACCEL_REDIRECT', default=not DEBUG)

# django
DEFAULT_FILE_STORAGE = 'django_uploads_app.storage.PrivateFileSystemStorage'  # !!
IGNORABLE_404_URLS = [re.compile(r'/filer_private_thumbnails/*')]  # ignore filer thumbnail generation errors

# django-filer
FILER_STORAGES = {
    'private': {
        'main': {
            'ENGINE': 'django_uploads_app.storage.PrivateFileSystemStorage',
            #'ENGINE': 'filer.storage.PrivateFileSystemStorage',
            'OPTIONS': {
                'location': os.path.abspath(os.path.join(MEDIA_ROOT, '../../private/')),
                'base_url': '/filer_private/',
            },
            'UPLOAD_TO': 'django_uploads_app.utils.generate_filer_filename',
            'UPLOAD_TO_PREFIX': '',
        },
        'thumbnails': {
            'ENGINE': 'django_uploads_app.storage.PrivateFileSystemStorage',
            'OPTIONS': {
                'location': os.path.abspath(os.path.join(MEDIA_ROOT, '../../filer-private/')),
                'base_url': '/filer_private_thumbnails/',
            },
        },
    }
}

FILER_ENABLE_PERMISSIONS = True
FILER_IS_PUBLIC_DEFAULT = False
FILER_DUMP_PAYLOAD = True
FILER_DEBUG = DEBUG
# save payload on dumpdata
FILER_DUMP_PAYLOAD = env.bool('FILER_DUMP_PAYLOAD', default=False)

Django settings for example project.  Generated by Cookiecutter Django Package # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # django-sso-app # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: don't run with debug turned on in production! # Application definition # if your app has other dependencies that need to be added to the site # they should be added here # required by django-sso-app # django-sso-app # Database # https://docs.djangoproject.com/en/1.9/ref/settings/#databases # Password validation # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators # Internationalization # https://docs.djangoproject.com/en/1.9/topics/i18n/ # file root # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.9/howto/static-files/ # file uploads # django-uploads # django # !! # ignore filer thumbnail generation errors # django-filer #'ENGINE': 'filer.storage.PrivateFileSystemStorage', # save payload on dumpdata