"""
Django settings for {{PROJECT_NAME}} project.

Generated by 'django-admin init_ndr_core' using Django 4.2.7.

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

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

from pathlib import Path
import os
from django.contrib import messages
from django.urls import reverse_lazy
from ndr_core.ndr_settings import NdrSettings

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "{{SECRET_KEY}}"

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

ALLOWED_HOSTS = ['{{ALLOWED_HOST}}']


# Application definition

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
]
# ADDITIONAL NDR CORE APPS
INSTALLED_APPS += NdrSettings.get_installed_apps()

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    'django.middleware.locale.LocaleMiddleware',                # Added
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "{{PROJECT_NAME}}.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_DIR / 'templates']
        ,
        "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 = "{{PROJECT_NAME}}.wsgi.application"


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

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}


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

# THIS IS THE DEFAULT LANGUAGE CODE OF YOUR NDR INSTANCE
LANGUAGE_CODE = "{{INITIAL_LANGUAGE_CODE}}"
LANGUAGE_COOKIE_NAME = 'django_ndr_language'
"""Default language code and cookie name."""

TIME_ZONE = "UTC"

USE_I18N = True
USE_TZ = True


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

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# NDR CORE SETTINGS
###################

# NDR CORE PATH SETTINGS
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = '/media/'
"""Sets the path for static and media files."""

# NDR ADMIN INTERFACE SETTINGS
LOGIN_URL = reverse_lazy('ndr_core:login')
LOGOUT_URL = reverse_lazy('ndr_core:logout')
LOGIN_REDIRECT_URL = reverse_lazy('ndr_core:dashboard')
"""Overwrites the default urls for the django authentication system."""

# NDR FORMS SETTINGS
CRISPY_TEMPLATE_PACK = 'bootstrap4'
"""Django crispy forms - used to render forms."""

FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
"""This renderer gives you complete control of how form and widget templates are sourced."""

# NDR TABLES SETTINGS
DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap4.html"
"""Django tables2 - used to render tables."""

# MESSAGE TAGS SETTINGS
MESSAGE_TAGS = {
        messages.DEBUG: 'alert-secondary',
        messages.INFO: 'alert-info',
        messages.SUCCESS: 'alert-success',
        messages.WARNING: 'alert-warning',
        messages.ERROR: 'alert-danger',
}
"""Bootstrap css classes to use to display django's built in message tags."""

# CORS SETTINGS
CORS_ALLOW_ALL_ORIGINS = True  # If this is used then `CORS_ALLOWED_ORIGINS` will not have any effect
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOWED_ORIGINS = [
    'https://avisblatt.dg-basel.hasdai.org',
]

CORS_ORIGIN_WHITELIST = (
    'http://localhost:8000',
)

CORS_ALLOW_HEADERS = [
    'accept',
    'accept-encoding',
    'authorization',
    'content-type',
    'dnt',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
]

# GEOIP SETTINGS
GEOIP_PATH = os.path.join('geoip/')
"""Needed for the geoip functionality."""

# CKEDITOR SETTINGS
CKEDITOR_UPLOAD_PATH = 'uploads/'
"""Needed for the ck-editor"""

# RECAPTCHA SETTINGS
SILENCED_SYSTEM_CHECKS = ['captcha.recaptcha_test_key_error']
RECAPTCHA_PUBLIC_KEY = 'y0uR3c4PtCh4pUbL1cK3y'
RECAPTCHA_PRIVATE_KEY = 'y0uR3c4PtCh4pr1v4t3K3y'
"""Recaptcha key to use for the captcha functionality for the contact form.. """