Skip to content
Snippets Groups Projects
settings.py 5.23 KiB
"""
Django settings for ShellValier project.

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

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

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

import os
import uuid

from django.urls import reverse_lazy

from .environment import get_environment, boolean_mapper, list_mapper_factory


# 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.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = get_environment('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = get_environment('DEBUG', mapper=boolean_mapper)

# for production
'''
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
X_FRAME_OPTIONS = 'DENY'
'''

ALLOWED_HOSTS = get_environment('ALLOWED_HOSTS', mapper=list_mapper_factory())

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'common.apps.CommonConfig',
    'connections.apps.ConnectionsConfig',
    'examples.apps.ExamplesConfig',
    'meanings.apps.MeaningsConfig',
    'semantics.apps.SemanticsConfig',
    'syntax.apps.SyntaxConfig',
    'entries.apps.EntriesConfig',
    'phrase_expansions.apps.PhraseExpansionsConfig',
    'dictionary_statistics.apps.DictionaryStatisticsConfig',
    'download.apps.DownloadConfig',
    'users.apps.UsersConfig',
    'crispy_forms',
    'django_extensions',
    'django_vite',
    'unifier.apps.UnifierConfig',
]

CRISPY_TEMPLATE_PACK = 'bootstrap4'
CRISPY_FAIL_SILENTLY = not DEBUG

MIDDLEWARE = [
    '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',
    'django.middleware.locale.LocaleMiddleware',
]

ROOT_URLCONF = 'shellvalier.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 = 'shellvalier.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': get_environment('DATABASE_NAME'),
        'USER': get_environment('DATABASE_USER'),
        'PASSWORD': get_environment('DATABASE_PASSWORD'),
        'HOST': get_environment('DATABASE_HOST'),
        'PORT': get_environment('DATABASE_PORT', mapper=int),
    }}


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

LANGUAGE_CODE = 'pl'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOCALE_PATHS = [
    'locale',
]


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

VERSION = get_environment('VERSION', default=str(uuid.uuid4()))
STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')
STATIC_URL = f'/static/'

DJANGO_VITE_ASSETS_PATH = os.path.join(BASE_DIR, 'frontend', 'dist')
DJANGO_VITE_DEV_MODE = DEBUG
DJANGO_VITE_STATIC_URL = "/"
DJANGO_VITE_DEV_SERVER_PORT = 8010

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'common/static/'),
    DJANGO_VITE_ASSETS_PATH,
]

LOGIN_URL = reverse_lazy('users:login')
LOGIN_REDIRECT_URL = reverse_lazy('dash')
LOGOUT_REDIRECT_URL = reverse_lazy('dash')

EMAIL_BACKEND = get_environment('EMAIL_BACKEND')
EMAIL_HOST = get_environment('EMAIL_HOST')
EMAIL_PORT = get_environment('EMAIL_PORT', mapper=int)
EMAIL_HOST_USER = get_environment('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = get_environment('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = get_environment('EMAIL_USE_TLS', mapper=boolean_mapper)
EMAIL_USE_SSL = get_environment('EMAIL_USE_SSL', mapper=boolean_mapper)

SUPER_LEXICOGRAPHS_GROUP_NAME = 'Super Leksykografowie'