<filename>app/settings.py
"""
Django settings for this project.

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

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

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

import os
from urllib.parse import urlparse
from opt.env_loader import load_env


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


# Environment variables
env = load_env(BASE_DIR)
envmode = env.get("PYTHON_ENV", "development")

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env.get("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.get("DEBUG", False)

ALLOWED_HOSTS = ["*"]

CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_CREDENTIALS = True


# Application definition

INSTALLED_APPS = [
    "app.config.CustomAdminConfig",  # "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    # "django.contrib.gis",
    "django.contrib.staticfiles",
    "django_extensions",
    "corsheaders",
    "graphene_django",
    "app.common",
    "app.profiles",
    "app.certificates",
]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    # "django.middleware.locale.LocaleMiddleware",
    "corsheaders.middleware.CorsMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "app.common.auth.middleware.JWTAuthenticationMiddleware",
    # "django.contrib.auth.middleware.RemoteUserMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "app.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 = "app.wsgi.application"


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

DB_SCHEMES = {
    "postgres": "django.db.backends.postgresql",
    "postgis": "django.contrib.gis.db.backends.postgis",
    "mysql": "django.db.backends.mysql",
    "mysql-connector": "mysql.connector.django",
    "mysqlgis": "django.contrib.gis.db.backends.mysql",
    "mssql": "sql_server.pyodbc",
    "oracle": "django.db.backends.oracle",
    "pyodbc": "sql_server.pyodbc",
    "redshift": "django_redshift_backend",
    "spatialite": "django.contrib.gis.db.backends.spatialite",
    "sqlite": "django.db.backends.sqlite3",
    "ldap": "ldapdb.backends.ldap",
}

database_url = urlparse(env.get("DATABASE_URL"))

DATABASES = {
    "default": {
        "ENGINE": DB_SCHEMES[database_url.scheme],
        "NAME": database_url.path[1:],
        "USER": database_url.username,
        "PASSWORD": database_url.password,
        "HOST": database_url.hostname,
        "PORT": database_url.port,
    },
}


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

AUTHENTICATION_BACKENDS = [
    "django.contrib.auth.backends.ModelBackend",
]

AUTH_USER_MODEL = "common.User"

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.10/topics/i18n/

# Provide a lists of languages which your site supports.
LANGUAGES = (
    ("tr", "Türkçe"),
    ("en", "English"),
)

LANGUAGE_CODE = "en"

TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True  # https://github.com/myyang/django-unixtimestampfield#django-settings


# Contains the path list where Django should look into for django.po files for all supported languages
LOCALE_PATHS = (os.path.join(BASE_DIR, "etc/locale"),)

LOCALE_DEFAULT = "tr-tr"

# FIXTURE_DIRS = (
#     os.path.join(PROJECT_DIR, "fixtures"),
# )


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

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

GRAPHENE = {
    "SCHEMA": "app.schema.schema",  # Where your Graphene schema lives
    "SCHEMA_INDENT": 2,
    "MIDDLEWARE": [
        "graphene_django.debug.DjangoDebugMiddleware",
        # "graphql_jwt.middleware.JSONWebTokenMiddleware",
    ],
}

AWS = {
    "AWS_ACCESS_KEY_ID": env.get("AWS_ACCESS_KEY_ID"),
    "AWS_SECRET_ACCESS_KEY": env.get("AWS_SECRET_ACCESS_KEY"),
    "AWS_DEFAULT_REGION": env.get("AWS_DEFAULT_REGION"),
    "COGNITO_USER_POOL_ID": env.get("COGNITO_USER_POOL_ID"),
    "COGNITO_CLIENT_ID": env.get("COGNITO_CLIENT_ID"),
    "COGNITO_CLIENT_SECRET": env.get("COGNITO_CLIENT_SECRET"),
}

LOGIN_OPTIONS = ["email", "phone"]

BOOK_DEFAULT_LOCK_UNTIL = 1
