"""
Django settings for proj project.

Generated by 'django-admin startproject' using Django 2.2.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

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


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/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 = ["*"]


SHARED_APPS = (
    'tenant_schemas',  # mandatory, should always be before any django app
    'customers', # you must list the app where your tenant model resides in

    'django.contrib.contenttypes',

    # everything below here is optional
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
)


TENANT_APPS = (
    # your tenant-specific apps
    # "users.apps.UsersConfig",
    # "books.apps.BooksConfig",
    # 'myapp.hotels',
    # 'myapp.houses',

    # 'django.contrib.auth',
    'django.contrib.contenttypes',
    # 'django.contrib.sessions',
    # 'django.contrib.sites',
    # 'django.contrib.messages',
    # 'django.contrib.admin',

    "users",
    "books",
)


# Application definition

INSTALLED_APPS = (
    'tenant_schemas',  # mandatory, should always be before any django app

    'customers',
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    # 'myapp.hotels',
    # 'myapp.houses',
    "users",
    "books",
    # "users.apps.UsersConfig",
    # "books.apps.BooksConfig",
    "rest_framework"
)


MIDDLEWARE = [
    "proj.middlewares.tenant_auth_middleware.TenantAuthMiddleware",
    "tenant_schemas.middleware.TenantMiddleware",

    'tenant_schemas.middleware.SuspiciousTenantMiddleware',
    'tenant_schemas.middleware.DefaultTenantMiddleware',

    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'proj.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            '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 = 'proj.wsgi.application'


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

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

DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.postgresql',
        'ENGINE': 'tenant_schemas.postgresql_backend',
        # 'NAME': 'tenantschemas5',
        # "NAME": "tenantschemas8",
        "NAME": "tenantschemas9",
        'USER': 'hygull',
        'PASSWORD': '<PASSWORD>',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

# Password validation
# https://docs.djangoproject.com/en/2.2/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/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static", "static_root")

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "static", "media_root")
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "files"),
]

# django-tenant-schemas
DATABASE_ROUTERS = (
    'tenant_schemas.routers.TenantSyncRouter',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
)

TENANT_MODEL = "customers.Client" # app.Model

# WARNINGS:
# ?: (tenant_schemas.W003) Your default storage engine is not tenant aware.
#     HINT: Set settings.DEFAULT_FILE_STORAGE to 'tenant_schemas.storage.TenantFileSystemStorage'
DEFAULT_FILE_STORAGE = 'tenant_schemas.storage.TenantFileSystemStorage'

# LOGGING = {
#     'filters': {
#         'tenant_context': {
#             '()': 'tenant_schemas.log.TenantContextFilter'
#         },
#     },
#     'formatters': {
#         'tenant_context': {
#             'format': '[%(schema_name)s:%(domain_url)s] '
#             '%(levelname)-7s %(asctime)s %(message)s',
#         },
#     },
#     'handlers': {
#         'console': {
#             'filters': ['tenant_context'],
#         },
#     },
# }
"""
Django settings for proj project.

Generated by 'django-admin startproject' using Django 2.2.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

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


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/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 = ["*"]


SHARED_APPS = (
    'tenant_schemas',  # mandatory, should always be before any django app
    'customers', # you must list the app where your tenant model resides in

    'django.contrib.contenttypes',

    # everything below here is optional
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
)


TENANT_APPS = (
    # your tenant-specific apps
    # "users.apps.UsersConfig",
    # "books.apps.BooksConfig",
    # 'myapp.hotels',
    # 'myapp.houses',

    # 'django.contrib.auth',
    'django.contrib.contenttypes',
    # 'django.contrib.sessions',
    # 'django.contrib.sites',
    # 'django.contrib.messages',
    # 'django.contrib.admin',

    "users",
    "books",
)


# Application definition

INSTALLED_APPS = (
    'tenant_schemas',  # mandatory, should always be before any django app

    'customers',
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    # 'myapp.hotels',
    # 'myapp.houses',
    "users",
    "books",
    # "users.apps.UsersConfig",
    # "books.apps.BooksConfig",
    "rest_framework"
)


MIDDLEWARE = [
    "proj.middlewares.tenant_auth_middleware.TenantAuthMiddleware",
    "tenant_schemas.middleware.TenantMiddleware",

    'tenant_schemas.middleware.SuspiciousTenantMiddleware',
    'tenant_schemas.middleware.DefaultTenantMiddleware',

    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'proj.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            '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 = 'proj.wsgi.application'


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

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

DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.postgresql',
        'ENGINE': 'tenant_schemas.postgresql_backend',
        # 'NAME': 'tenantschemas5',
        # "NAME": "tenantschemas8",
        "NAME": "tenantschemas9",
        'USER': 'hygull',
        'PASSWORD': '<PASSWORD>',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

# Password validation
# https://docs.djangoproject.com/en/2.2/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/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static", "static_root")

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "static", "media_root")
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "files"),
]

# django-tenant-schemas
DATABASE_ROUTERS = (
    'tenant_schemas.routers.TenantSyncRouter',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
)

TENANT_MODEL = "customers.Client" # app.Model

# WARNINGS:
# ?: (tenant_schemas.W003) Your default storage engine is not tenant aware.
#     HINT: Set settings.DEFAULT_FILE_STORAGE to 'tenant_schemas.storage.TenantFileSystemStorage'
DEFAULT_FILE_STORAGE = 'tenant_schemas.storage.TenantFileSystemStorage'

# LOGGING = {
#     'filters': {
#         'tenant_context': {
#             '()': 'tenant_schemas.log.TenantContextFilter'
#         },
#     },
#     'formatters': {
#         'tenant_context': {
#             'format': '[%(schema_name)s:%(domain_url)s] '
#             '%(levelname)-7s %(asctime)s %(message)s',
#         },
#     },
#     'handlers': {
#         'console': {
#             'filters': ['tenant_context'],
#         },
#     },
# }
Django settings for proj project.  Generated by 'django-admin startproject' using Django 2.2.  For more information on this file, see https://docs.djangoproject.com/en/2.2/topics/settings/  For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: don't run with debug turned on in production! # mandatory, should always be before any django app # you must list the app where your tenant model resides in # everything below here is optional # your tenant-specific apps # "users.apps.UsersConfig", # "books.apps.BooksConfig", # 'myapp.hotels', # 'myapp.houses', # 'django.contrib.auth', # 'django.contrib.sessions', # 'django.contrib.sites', # 'django.contrib.messages', # 'django.contrib.admin', # Application definition # mandatory, should always be before any django app # 'myapp.hotels', # 'myapp.houses', # "users.apps.UsersConfig", # "books.apps.BooksConfig", # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases # DATABASES = { #     'default': { #         'ENGINE': 'django.db.backends.sqlite3', #         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), #     } # } # 'ENGINE': 'django.db.backends.postgresql', # 'NAME': 'tenantschemas5', # "NAME": "tenantschemas8", # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ # django-tenant-schemas # app.Model # WARNINGS: # ?: (tenant_schemas.W003) Your default storage engine is not tenant aware. #     HINT: Set settings.DEFAULT_FILE_STORAGE to 'tenant_schemas.storage.TenantFileSystemStorage' # LOGGING = { #     'filters': { #         'tenant_context': { #             '()': 'tenant_schemas.log.TenantContextFilter' #         }, #     }, #     'formatters': { #         'tenant_context': { #             'format': '[%(schema_name)s:%(domain_url)s] ' #             '%(levelname)-7s %(asctime)s %(message)s', #         }, #     }, #     'handlers': { #         'console': { #             'filters': ['tenant_context'], #         }, #     }, # }