201 lines
5.2 KiB
Python
201 lines
5.2 KiB
Python
"""
|
|
Django settings for core project.
|
|
|
|
Generated by 'django-admin startproject' 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/
|
|
"""
|
|
import environ
|
|
import os
|
|
import datetime as dt
|
|
from pathlib import Path
|
|
|
|
from common.const_and_variables import BOOLEAN_VALIDS
|
|
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
env = environ.Env(
|
|
DEBUG=(bool, False)
|
|
)
|
|
|
|
# Leer el archivo .env
|
|
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
|
|
|
|
API_BASE_URL = env('API_BASE_URL')
|
|
|
|
# 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 = env('SECRET_KEY')
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = env('DEBUG', False) in BOOLEAN_VALIDS
|
|
|
|
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=[])
|
|
CSRF_TRUSTED_ORIGINS = env.list('CSRF_TRUSTED_ORIGINS', default=[])
|
|
|
|
|
|
CORS_ALLOW_ALL_ORIGINS = True if DEBUG else ()
|
|
|
|
|
|
# Application definition
|
|
|
|
DJANGO_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
]
|
|
|
|
EXTERNAL_APPS = [
|
|
'rest_framework',
|
|
'rest_framework_simplejwt',
|
|
'rest_framework_simplejwt.token_blacklist',
|
|
'corsheaders',
|
|
'drf_yasg',
|
|
'django_filters',
|
|
]
|
|
|
|
PROJECT_APPS = [
|
|
'apps.users',
|
|
'apps.orders'
|
|
]
|
|
|
|
INSTALLED_APPS = EXTERNAL_APPS + DJANGO_APPS + PROJECT_APPS
|
|
|
|
AUTH_USER_MODEL = 'users.CustomUser'
|
|
|
|
|
|
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',
|
|
]
|
|
|
|
ROOT_URLCONF = 'core.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 = 'core.wsgi.application'
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': env('DATABASE_ENGINE'),
|
|
'PASSWORD': env('DATABASE_PASSWORD'),
|
|
'NAME': env('DATABASE_NAME'),
|
|
'USER': env('DATABASE_USER'),
|
|
'HOST': env('DATABASE_HOST'),
|
|
'PORT': env('DATABASE_PORT'),
|
|
'OPTIONS': {
|
|
'client_encoding': 'UTF-8'
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
# 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/
|
|
|
|
LANGUAGE_CODE = 'es-CO'
|
|
|
|
LANGUAGES = (
|
|
('es', 'Spanish'),
|
|
('en', 'English'),
|
|
)
|
|
|
|
DATE_FORMAT = 'd-m-Y' # Formato de fecha: día-mes-año
|
|
DATETIME_FORMAT = 'd-m-Y H:i' # Formato de fecha y hora
|
|
USE_L10N = False
|
|
|
|
TIME_ZONE = 'America/Bogota'
|
|
USE_I18N = True
|
|
USE_L10N = True
|
|
USE_TZ = True
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
|
|
|
|
MEDIA_URL = '/media/'
|
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
|
|
|
|
X_FRAME_OPTIONS = "SAMEORIGIN"
|
|
SILENCED_SYSTEM_CHECKS = ["security.W019"]
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
|
),
|
|
'EXCEPTION_HANDLER': 'common.exceptions.custom_validation_error',
|
|
'DATETIME_FORMAT': "%d-%m-%Y %H:%M:%S",
|
|
"DATE_FORMAT": "%d-%m-%Y"
|
|
}
|
|
|
|
SIMPLE_JWT = {
|
|
"ACCESS_TOKEN_LIFETIME": dt.timedelta(
|
|
days=env.int('ACCESS_TOKEN_LIFETIME_DAYS', default=0),
|
|
hours=env.int('ACCESS_TOKEN_LIFETIME_HOURS', default=0),
|
|
minutes=env.int('ACCESS_TOKEN_LIFETIME_MINUTES', default=10)),
|
|
"REFRESH_TOKEN_LIFETIME": dt.timedelta(
|
|
days=env.int('REFRESH_TOKEN_LIFETIME_DAYS', default=0),
|
|
hours=env.int('REFRESH_TOKEN_LIFETIME_HOURS', default=0),
|
|
minutes=env.int('REFRESH_TOKEN_LIFETIME_MINUTES', default=30)),
|
|
} |