Mudanza de repo
This commit is contained in:
3
config/__init__.py
Normal file
3
config/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .celery import app as celery_app
|
||||
|
||||
__all__ = ('celery_app',)
|
||||
16
config/asgi.py
Normal file
16
config/asgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for config project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
8
config/celery.py
Normal file
8
config/celery.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import os
|
||||
from celery import Celery
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
app = Celery('config')
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
app.autodiscover_tasks()
|
||||
352
config/settings.py
Normal file
352
config/settings.py
Normal file
@@ -0,0 +1,352 @@
|
||||
# Celery Beat Schedule
|
||||
from celery.schedules import crontab
|
||||
|
||||
|
||||
CELERY_BEAT_SCHEDULE = {
|
||||
# Ejecutar pedimento completo de 5:00 a 22:00 (cada hora)
|
||||
'creacion-servicio-pedimento-completo': {
|
||||
'task': 'api.customs.tasks.internal_services.crear_todos_los_servicios',
|
||||
'schedule': crontab(minute=0, hour='5-22'),
|
||||
},
|
||||
# Ejecutar pedimento completo de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-pedimentos-completos-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_pedimento_completo',
|
||||
'schedule': crontab(minute=0, hour='5-22'),
|
||||
},
|
||||
# Ejecutar partidas de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-partidas-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_partidas_pedimento',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar coves de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-coves-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_coves',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar remesas de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-remesas-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_remesas',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar acuse coves de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-acuse-coves-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_acuseCoves',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar acuse de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-acuse-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_acuse',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar edocs solo de 23:00 a 4:59 (cada hora en ese rango)
|
||||
'ejecutar-edocs-noche': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_edocs',
|
||||
'schedule': crontab(minute=42, hour='23,0,1,2,3,4'),
|
||||
},
|
||||
|
||||
}
|
||||
"""
|
||||
Django settings for config project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 5.2.3.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.2/ref/settings/
|
||||
"""
|
||||
import os
|
||||
import ssl
|
||||
import smtplib
|
||||
|
||||
from pathlib import Path
|
||||
from corsheaders.defaults import default_headers
|
||||
from datetime import timedelta
|
||||
|
||||
# --- SOLO PARA DESARROLLO: Desactivar verificación de certificados SSL en SMTP ---
|
||||
smtplib.SMTP_SSL.default_context = ssl._create_unverified_context
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import re
|
||||
|
||||
# Cargar variables de entorno desde un archivo .env
|
||||
load_dotenv()
|
||||
|
||||
# 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/5.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = os.getenv('SECRET_KEY')
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = os.getenv('DEBUG', 'True') == 'True'
|
||||
|
||||
ALLOWED_HOSTS = [
|
||||
'localhost'
|
||||
,'host.docker.internal'
|
||||
,'192.168.1.195'
|
||||
,'127.0.0.1'
|
||||
,'74.208.78.59'
|
||||
,'api.efc-aduanasoft.com'
|
||||
,'backend'
|
||||
,'backend:8000'
|
||||
,'0.0.0.0'
|
||||
,'192.168.1.79'
|
||||
]
|
||||
|
||||
SITE_URL = os.getenv('SITE_URL')
|
||||
SERVICE_API_URL = os.getenv('SERVICE_API_URL')
|
||||
|
||||
# Application definition
|
||||
BASE_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
THIRD_APPS = [
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'rest_framework_simplejwt',
|
||||
'drf_yasg',
|
||||
'corsheaders',
|
||||
'django_filters',
|
||||
'rest_framework_simplejwt.token_blacklist',
|
||||
]
|
||||
|
||||
OWN_APPS = [
|
||||
'api.customs',
|
||||
'api.record',
|
||||
'api.organization',
|
||||
'api.licence',
|
||||
'api.cuser',
|
||||
'api.datastage',
|
||||
'api.vucem',
|
||||
'api.logger',
|
||||
'api.notificaciones',
|
||||
'api.reports',
|
||||
'api.cards',
|
||||
]
|
||||
|
||||
INSTALLED_APPS = BASE_APPS + THIRD_APPS + OWN_APPS
|
||||
MIDDLEWARE = [
|
||||
'corsheaders.middleware.CorsMiddleware', # Debe ir antes de CommonMiddleware
|
||||
'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',
|
||||
'api.logger.middleware.RequestLoggingMiddleware',
|
||||
'api.logger.middleware.ErrorLoggingMiddleware',
|
||||
]
|
||||
|
||||
# Crear directorio de logs
|
||||
LOGS_DIR = BASE_DIR / 'logs'
|
||||
LOGS_DIR.mkdir(exist_ok=True)
|
||||
|
||||
# Configuración de logging unificada
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
},
|
||||
},
|
||||
'root': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
'celery': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# Configuración para desarrollo y producción
|
||||
if DEBUG:
|
||||
CORS_ALLOW_ALL_ORIGINS = True
|
||||
CORS_ALLOW_CREDENTIALS = True
|
||||
SESSION_COOKIE_SECURE = False
|
||||
CSRF_COOKIE_SECURE = False
|
||||
USE_X_FORWARDED_HOST = False
|
||||
else:
|
||||
CORS_ALLOW_ALL_ORIGINS = False
|
||||
CORS_ALLOW_CREDENTIALS = False
|
||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||
CORS_ALLOWED_ORIGINS = os.getenv('CORS_ALLOWED_ORIGINS').split(',')
|
||||
CSRF_COOKIE_SECURE = True
|
||||
SESSION_COOKIE_SECURE = True
|
||||
USE_X_FORWARDED_HOST = True
|
||||
|
||||
CORS_ALLOW_HEADERS = list(default_headers) + [
|
||||
'access-control-allow-origin',
|
||||
'access-control-allow-credentials',
|
||||
]
|
||||
|
||||
# # JWT Authentication settings
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
||||
'rest_framework.authentication.TokenAuthentication', # Añade esta línea
|
||||
],
|
||||
'DEFAULT_PERMISSION_CLASSES': [
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
],
|
||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||
'PAGE_SIZE': 20,
|
||||
'DEFAULT_FILTER_BACKENDS': [
|
||||
'django_filters.rest_framework.DjangoFilterBackend',
|
||||
'rest_framework.filters.SearchFilter',
|
||||
'rest_framework.filters.OrderingFilter',
|
||||
],
|
||||
}
|
||||
|
||||
# Configuración de Swagger
|
||||
SWAGGER_SETTINGS = {
|
||||
"DEFAULT_AUTO_SCHEMA_CLASS": "core.swagger.CustomAutoSchema",
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
||||
),
|
||||
'SECURITY_DEFINITIONS': {
|
||||
'Bearer': {
|
||||
'type': 'apiKey',
|
||||
'name': 'Authorization',
|
||||
'in': 'header',
|
||||
'description': 'JWT Authorization header using the Bearer scheme. Example: "Authorization: Bearer {token}"'
|
||||
}
|
||||
},
|
||||
'USE_SESSION_AUTH': False,
|
||||
'LOGIN_URL': '/api/v1/token/',
|
||||
'LOGOUT_URL': '/api/v1/auth/logout/',
|
||||
'DOC_EXPANSION': 'None',
|
||||
}
|
||||
|
||||
# Configuración adicional para ReDoc
|
||||
REDOC_SETTINGS = {
|
||||
'LAZY_RENDERING': False,
|
||||
'HIDE_HOSTNAME': False,
|
||||
'EXPAND_RESPONSES': 'all',
|
||||
'PATH_IN_MIDDLE': True,
|
||||
}
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
"https://api.efc-aduanasoft.com",
|
||||
"http://192.168.1.195",
|
||||
"http://192.168.1.195:8000"
|
||||
]
|
||||
|
||||
# URL Configuration
|
||||
ROOT_URLCONF = 'config.urls'
|
||||
|
||||
# Template configuration
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR / 'templates'],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'config.wsgi.application'
|
||||
|
||||
# Database
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE' : 'django.db.backends.postgresql',
|
||||
'NAME' : os.getenv('DB_NAME'),
|
||||
'USER' : os.getenv('DB_USER'),
|
||||
'PASSWORD' : os.getenv('DB_PASSWORD'),
|
||||
'HOST' : os.getenv('DB_HOST'),
|
||||
'PORT' : os.getenv('DB_PORT'),
|
||||
}
|
||||
}
|
||||
|
||||
# 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 = 'en-us'
|
||||
TIME_ZONE = 'America/Ojinaga' # Zona horaria de Cd. Juárez, Chihuahua
|
||||
USE_I18N = True
|
||||
USE_TZ = True
|
||||
|
||||
# Static files
|
||||
STATIC_URL = 'static/'
|
||||
if DEBUG:
|
||||
STATICFILES_DIRS = [BASE_DIR / 'staticfiles']
|
||||
else:
|
||||
STATICFILES_DIRS = []
|
||||
STATIC_ROOT = BASE_DIR / 'static'
|
||||
|
||||
MEDIA_URL = '/media/'
|
||||
MEDIA_ROOT = BASE_DIR / 'media'
|
||||
|
||||
# Default primary key field type
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
AUTH_USER_MODEL = 'cuser.CustomUser'
|
||||
|
||||
# Configuración SMTP para envío de correos electrónicos
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_HOST = os.getenv('EMAIL_HOST')
|
||||
EMAIL_PORT = int(os.getenv('EMAIL_PORT'))
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER')
|
||||
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD')
|
||||
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
|
||||
|
||||
# Configuración Celery
|
||||
CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL', 'redis://redis:6379/0')
|
||||
CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND', 'redis://redis:6379/0')
|
||||
CELERY_TIMEZONE = 'America/Mexico_City'
|
||||
|
||||
# Configuración para procesamiento asíncrono nativo de Django
|
||||
ASGI_APPLICATION = 'config.asgi.application'
|
||||
|
||||
SIMPLE_JWT = {
|
||||
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=30), # Tokens de acceso cortos por seguridad
|
||||
'REFRESH_TOKEN_LIFETIME': timedelta(days=5), # Refresh token de 5 días
|
||||
'ROTATE_REFRESH_TOKENS': True, # Rotar refresh tokens para mayor seguridad
|
||||
'BLACKLIST_AFTER_ROTATION': True,
|
||||
'AUTH_HEADER_TYPES': ('Bearer',),
|
||||
}
|
||||
|
||||
|
||||
59
config/urls.py
Normal file
59
config/urls.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include, re_path
|
||||
from django.conf import settings
|
||||
#
|
||||
from rest_framework import permissions
|
||||
from drf_yasg.views import get_schema_view
|
||||
from drf_yasg import openapi
|
||||
|
||||
from django.conf.urls.static import static
|
||||
|
||||
from rest_framework_simplejwt.views import (
|
||||
TokenObtainPairView,
|
||||
TokenRefreshView,
|
||||
)
|
||||
|
||||
schema_view = get_schema_view(
|
||||
openapi.Info(
|
||||
title="EFC API",
|
||||
default_version='v1',
|
||||
description="API para el sistema EFC V2 - Gestión de Expediente electronicos de Comercio Exterior",
|
||||
terms_of_service="https://www.google.com/policies/terms/",
|
||||
contact=openapi.Contact(email="contact@aduanasoft.com.mx"),
|
||||
license=openapi.License(name="MIT License"),
|
||||
),
|
||||
public=True,
|
||||
permission_classes=(permissions.AllowAny,),
|
||||
authentication_classes=[], # Desactivar auth para ver la documentación
|
||||
# url='https://api.efc-aduanasoft.com/api/v1'
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/v1/', include('api.licence.urls')),
|
||||
|
||||
# JWT Authentication
|
||||
path('api/v1/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
|
||||
path('api/v1/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
|
||||
path('api/v1/user/', include(('api.cuser.urls', 'cuser'), namespace='cuser')), # Custom user app
|
||||
|
||||
#path('api-auth/', include('rest_framework.urls')),
|
||||
path('api/v1/swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||
path('api/v1/redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
|
||||
|
||||
path('api/v1/customs/', include('api.customs.urls')),
|
||||
path('api/v1/organization/', include('api.organization.urls')),
|
||||
path('api/v1/record/', include('api.record.urls')),
|
||||
path('api/v1/datastage/', include('api.datastage.urls')),
|
||||
path('api/v1/vucem/', include('api.vucem.urls')),
|
||||
path('api/v1/logger/', include('api.logger.urls')), # Logger app
|
||||
path('api/v1/notificaciones/', include('api.notificaciones.urls')), # Notificaciones app
|
||||
path('api/v1/cards/', include('api.cards.urls')), # Cards app
|
||||
path('api/v1/reports/', include('api.reports.urls')), # Reports app
|
||||
]
|
||||
# En producción, los archivos media son servidos por Nginx
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL + 'profile_pictures/', document_root=settings.MEDIA_ROOT / 'profile_pictures')
|
||||
urlpatterns += static(settings.MEDIA_URL + 'membretado/', document_root=settings.MEDIA_ROOT / 'profile_pictures')
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
||||
16
config/wsgi.py
Normal file
16
config/wsgi.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for config project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user