forked from val-lop20/Pagina-de-Asistencia-MAC
161 lines
4.7 KiB
Python
161 lines
4.7 KiB
Python
"""
|
|
Django settings for mac_attendance project - BASE configuration.
|
|
|
|
Configuración compartida entre todos los entornos (desarrollo y producción).
|
|
NO incluye configuraciones específicas de entorno como DEBUG, ALLOWED_HOSTS, etc.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from datetime import timedelta
|
|
from decouple import config
|
|
import os
|
|
|
|
# Build paths inside the project
|
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = config('SECRET_KEY')
|
|
|
|
# Application definition
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'rest_framework',
|
|
'rest_framework_simplejwt',
|
|
'corsheaders',
|
|
'import_export',
|
|
'authentication',
|
|
'events',
|
|
'attendance',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'corsheaders.middleware.CorsMiddleware',
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'django.middleware.common.CommonMiddleware',
|
|
'authentication.middleware.DisableCSRFOnAPIMiddleware', # Exentar API de CSRF (usamos JWT)
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
'authentication.middleware.AuditMiddleware', # Auditoría de seguridad
|
|
]
|
|
|
|
ROOT_URLCONF = 'mac_attendance.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 = 'mac_attendance.wsgi.application'
|
|
|
|
# Database Configuration - PostgreSQL
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.postgresql',
|
|
'NAME': config('DB_NAME', default='mac_attendance'),
|
|
'USER': config('DB_USER', default='mac_user'),
|
|
'PASSWORD': config('DB_PASSWORD', default='mac_password_2024_secure'),
|
|
'HOST': config('DB_HOST', default='db'),
|
|
'PORT': config('DB_PORT', default='5432'),
|
|
'CONN_MAX_AGE': 600, # Conexiones persistentes para mejor rendimiento
|
|
'OPTIONS': {
|
|
'connect_timeout': 10,
|
|
}
|
|
}
|
|
}
|
|
|
|
# Password validation
|
|
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
|
|
LANGUAGE_CODE = 'es-mx'
|
|
TIME_ZONE = 'America/Mexico_City'
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
|
|
|
# Media files
|
|
MEDIA_URL = '/media/'
|
|
MEDIA_ROOT = BASE_DIR / 'media'
|
|
|
|
# Default primary key field type
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
# CORS settings
|
|
CORS_ALLOW_CREDENTIALS = True
|
|
|
|
# Exentar todas las rutas de API del CSRF check (usamos JWT para seguridad)
|
|
CSRF_EXEMPT_URLS = [r'^api/.*$']
|
|
|
|
# Django REST Framework
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
|
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
|
'rest_framework.authentication.SessionAuthentication', # Mantener para Django admin
|
|
],
|
|
'DEFAULT_PERMISSION_CLASSES': [
|
|
'rest_framework.permissions.IsAuthenticated',
|
|
],
|
|
'EXCEPTION_HANDLER': 'mac_attendance.exceptions.custom_exception_handler',
|
|
}
|
|
|
|
# JWT Settings
|
|
SIMPLE_JWT = {
|
|
'ACCESS_TOKEN_LIFETIME': timedelta(hours=1),
|
|
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
|
|
'ROTATE_REFRESH_TOKENS': True,
|
|
'BLACKLIST_AFTER_ROTATION': False,
|
|
'UPDATE_LAST_LOGIN': True,
|
|
|
|
'ALGORITHM': 'HS256',
|
|
'SIGNING_KEY': SECRET_KEY,
|
|
'VERIFYING_KEY': None,
|
|
|
|
'AUTH_HEADER_TYPES': ('Bearer',),
|
|
'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
|
|
'USER_ID_FIELD': 'id',
|
|
'USER_ID_CLAIM': 'user_id',
|
|
|
|
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
|
|
'TOKEN_TYPE_CLAIM': 'token_type',
|
|
}
|
|
|
|
# Crear directorio de logs si no existe
|
|
LOGS_DIR = BASE_DIR / 'logs'
|
|
if not os.path.exists(LOGS_DIR):
|
|
os.makedirs(LOGS_DIR)
|