Compare commits
5 Commits
dev
...
f6892b2166
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6892b2166 | ||
|
|
d2c91d5196 | ||
|
|
d735d73322 | ||
|
|
197cff011f | ||
|
|
590e18e994 |
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,2 +1,5 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
# Auto detect text files and perform LF normalization
|
||||||
* text=auto
|
* text=auto
|
||||||
|
|
||||||
|
# Shell scripts: forzar LF siempre (evita CRLF en Windows que rompe Docker)
|
||||||
|
*.sh text eol=lf
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -140,9 +140,11 @@ python manage.py migrate <app_name> zero
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Docker — Producción
|
## Docker — Local y Producción
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
cd deployments
|
||||||
|
|
||||||
# Construir e iniciar
|
# Construir e iniciar
|
||||||
docker-compose up --build -d
|
docker-compose up --build -d
|
||||||
|
|
||||||
@@ -158,6 +160,16 @@ docker-compose down -v
|
|||||||
|
|
||||||
El contenedor expone el puerto **8000**.
|
El contenedor expone el puerto **8000**.
|
||||||
|
|
||||||
|
### Crear superusuario (primera vez con Docker)
|
||||||
|
|
||||||
|
Una vez los contenedores estén corriendo:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose exec web sh -c "cd /app/app && python manage.py createsuperuser"
|
||||||
|
```
|
||||||
|
|
||||||
|
Introduce usuario, email y contraseña cuando lo pida. Estas credenciales son las que usarás para entrar en el panel web (`web_interno`) y en `/admin/`.
|
||||||
|
|
||||||
Para producción con PostgreSQL, asegúrate de que `.env` tenga `DB_HOST` apuntando al host correcto (puede ser el nombre del servicio en la red Docker).
|
Para producción con PostgreSQL, asegúrate de que `.env` tenga `DB_HOST` apuntando al host correcto (puede ser el nombre del servicio en la red Docker).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -175,6 +175,11 @@ LOGGING = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- URLs de APIs internas (via red Docker saas_network) ---
|
||||||
|
API_BACKOFFICE = os.getenv('API_BACKOFFICE', 'http://api_backoffice:8001')
|
||||||
|
API_COMUNICACIONES = os.getenv('API_COMUNICACIONES', 'http://api_comunicaciones:8002')
|
||||||
|
API_DOCUMENTACION = os.getenv('API_DOCUMENTACION', 'http://api_documentacion:8003')
|
||||||
|
|
||||||
# --- CONFIGURACIONES PERSONALIZADAS DE LA APP ---
|
# --- CONFIGURACIONES PERSONALIZADAS DE LA APP ---
|
||||||
|
|
||||||
# Leemos la variable del .env (cargado previamente con load_dotenv)
|
# Leemos la variable del .env (cargado previamente con load_dotenv)
|
||||||
|
|||||||
60
app/common/http_client.py
Normal file
60
app/common/http_client.py
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import urllib.request
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
BACKOFFICE_URL = os.getenv('BACKOFFICE_URL', 'http://django_app_backoffice:8000')
|
||||||
|
COMUNICACIONES_URL = os.getenv('COMUNICACIONES_URL', 'http://django_app_comunicaciones:8000')
|
||||||
|
DOCUMENTACION_URL = os.getenv('DOCUMENTACION_URL', 'http://django_app_documentacion:8000')
|
||||||
|
|
||||||
|
|
||||||
|
def _post(url, payload):
|
||||||
|
data = json.dumps(payload).encode('utf-8')
|
||||||
|
req = urllib.request.Request(
|
||||||
|
url, data=data,
|
||||||
|
headers={'Content-Type': 'application/json'},
|
||||||
|
method='POST'
|
||||||
|
)
|
||||||
|
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||||
|
return json.loads(resp.read())
|
||||||
|
|
||||||
|
|
||||||
|
# --- Backoffice ---
|
||||||
|
def backoffice_obtener_usuario(params):
|
||||||
|
return _post(f'{BACKOFFICE_URL}/api/usuarios/obtener/', params)
|
||||||
|
|
||||||
|
def backoffice_crear_usuario(params):
|
||||||
|
return _post(f'{BACKOFFICE_URL}/api/usuarios/guardar/', params)
|
||||||
|
|
||||||
|
def backoffice_obtener_cliente(params):
|
||||||
|
return _post(f'{BACKOFFICE_URL}/api/clientes/obtener/', params)
|
||||||
|
|
||||||
|
def backoffice_crear_cliente(params):
|
||||||
|
return _post(f'{BACKOFFICE_URL}/api/clientes/guardar/', params)
|
||||||
|
|
||||||
|
def backoffice_obtener_contrato(params):
|
||||||
|
return _post(f'{BACKOFFICE_URL}/api/contratos/obtener/', params)
|
||||||
|
|
||||||
|
def backoffice_crear_contrato(params):
|
||||||
|
return _post(f'{BACKOFFICE_URL}/api/contratos/guardar/', params)
|
||||||
|
|
||||||
|
|
||||||
|
# --- Comunicaciones ---
|
||||||
|
def comunicaciones_enviar_email(params):
|
||||||
|
return _post(f'{COMUNICACIONES_URL}/api/email/enviar/', params)
|
||||||
|
|
||||||
|
def comunicaciones_enviar_sms(params):
|
||||||
|
return _post(f'{COMUNICACIONES_URL}/api/sms/enviar/', params)
|
||||||
|
|
||||||
|
def comunicaciones_registrar_webhook(params):
|
||||||
|
return _post(f'{COMUNICACIONES_URL}/api/webhooks/registrar/', params)
|
||||||
|
|
||||||
|
|
||||||
|
# --- Documentacion ---
|
||||||
|
def documentacion_generar_pdf(params):
|
||||||
|
return _post(f'{DOCUMENTACION_URL}/api/generation/pdf/', params)
|
||||||
|
|
||||||
|
def documentacion_obtener_template(params):
|
||||||
|
return _post(f'{DOCUMENTACION_URL}/api/templates/obtener/', params)
|
||||||
|
|
||||||
|
def documentacion_guardar_documento(params):
|
||||||
|
return _post(f'{DOCUMENTACION_URL}/api/storage/guardar/', params)
|
||||||
100
app/general/request_api.py
Normal file
100
app/general/request_api.py
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import json
|
||||||
|
import requests
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
class Request_API:
|
||||||
|
"""Dispatcher de llamadas HTTP internas hacia las APIs especializadas."""
|
||||||
|
|
||||||
|
def _post(self, base_url, url_path, data):
|
||||||
|
url = base_url.rstrip('/') + '/' + url_path.lstrip('/')
|
||||||
|
headers = {'Content-Type': 'application/json'}
|
||||||
|
response = requests.post(url, data=json.dumps(data), headers=headers, timeout=30)
|
||||||
|
return response.json(), response.status_code
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# api_backoffice #
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
|
||||||
|
def backoffice_get_parameterized(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/get_parameterized/', data)
|
||||||
|
|
||||||
|
def backoffice_get_dataComplex(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/get_dataComplex/', data)
|
||||||
|
|
||||||
|
def backoffice_set_parameterized(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/set_parameterized/', data)
|
||||||
|
|
||||||
|
def backoffice_set_data2(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/set_data2/', data)
|
||||||
|
|
||||||
|
def backoffice_set_data_batch(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/set_data_batch/', data)
|
||||||
|
|
||||||
|
def backoffice_get_BBDD(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/get_BBDD/', data)
|
||||||
|
|
||||||
|
def backoffice_set_BBDD(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/set_BBDD/', data)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# api_comunicaciones #
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
|
||||||
|
def comunicaciones_get_parameterized(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/general/get_parameterized/', data)
|
||||||
|
|
||||||
|
def comunicaciones_get_dataComplex(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/general/get_dataComplex/', data)
|
||||||
|
|
||||||
|
def comunicaciones_set_parameterized(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/general/set_parameterized/', data)
|
||||||
|
|
||||||
|
def comunicaciones_set_data2(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/general/set_data2/', data)
|
||||||
|
|
||||||
|
def comunicaciones_set_data_batch(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/general/set_data_batch/', data)
|
||||||
|
|
||||||
|
def comunicaciones_get_BBDD(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/general/get_BBDD/', data)
|
||||||
|
|
||||||
|
def comunicaciones_set_BBDD(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/general/set_BBDD/', data)
|
||||||
|
|
||||||
|
def comunicaciones_enviar_email(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/email/enviar/', data)
|
||||||
|
|
||||||
|
def comunicaciones_enviar_sms(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/sms/enviar/', data)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# api_documentacion #
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
|
||||||
|
def documentacion_get_parameterized(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/general/get_parameterized/', data)
|
||||||
|
|
||||||
|
def documentacion_get_dataComplex(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/general/get_dataComplex/', data)
|
||||||
|
|
||||||
|
def documentacion_set_parameterized(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/general/set_parameterized/', data)
|
||||||
|
|
||||||
|
def documentacion_set_data2(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/general/set_data2/', data)
|
||||||
|
|
||||||
|
def documentacion_set_data_batch(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/general/set_data_batch/', data)
|
||||||
|
|
||||||
|
def documentacion_get_BBDD(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/general/get_BBDD/', data)
|
||||||
|
|
||||||
|
def documentacion_set_BBDD(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/general/set_BBDD/', data)
|
||||||
|
|
||||||
|
def documentacion_generar_pdf(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/generation/pdf/', data)
|
||||||
|
|
||||||
|
def documentacion_guardar(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/storage/guardar/', data)
|
||||||
@@ -5,3 +5,4 @@ python-dotenv==1.0.1
|
|||||||
djangorestframework
|
djangorestframework
|
||||||
django-cors-headers
|
django-cors-headers
|
||||||
djangorestframework-simplejwt
|
djangorestframework-simplejwt
|
||||||
|
requests==2.32.3
|
||||||
@@ -36,6 +36,13 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
- saas_network
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
saas_network:
|
||||||
|
external: true
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ python-dotenv==1.0.1
|
|||||||
djangorestframework
|
djangorestframework
|
||||||
django-cors-headers
|
django-cors-headers
|
||||||
djangorestframework-simplejwt
|
djangorestframework-simplejwt
|
||||||
|
requests==2.32.3
|
||||||
@@ -5,33 +5,7 @@
|
|||||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
||||||
"_postman_id": "django-core-base-collection"
|
"_postman_id": "django-core-base-collection"
|
||||||
},
|
},
|
||||||
"variable": [
|
"variable": [],
|
||||||
{
|
|
||||||
"key": "base_url",
|
|
||||||
"value": "http://localhost:8000",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "access_token",
|
|
||||||
"value": "",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "refresh_token",
|
|
||||||
"value": "",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "username",
|
|
||||||
"value": "admin",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "password",
|
|
||||||
"value": "admin",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"item": [
|
"item": [
|
||||||
{
|
{
|
||||||
"name": "Auth",
|
"name": "Auth",
|
||||||
|
|||||||
35
postman_environments.json
Normal file
35
postman_environments.json
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"local": {
|
||||||
|
"id": "ftt19d5vxuj",
|
||||||
|
"v": 2,
|
||||||
|
"name": "LOCAL",
|
||||||
|
"variables": [
|
||||||
|
{ "key": "base_url", "secret": false, "initialValue": "http://localhost:8000", "currentValue": "http://localhost:8000" },
|
||||||
|
{ "key": "username", "secret": false, "initialValue": "admin", "currentValue": "admin" },
|
||||||
|
{ "key": "password", "secret": false, "initialValue": "admin", "currentValue": "admin" },
|
||||||
|
{ "key": "access_token", "secret": false, "initialValue": "", "currentValue": "" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"dev": {
|
||||||
|
"id": "x8jh10qysfo",
|
||||||
|
"v": 2,
|
||||||
|
"name": "DEV",
|
||||||
|
"variables": [
|
||||||
|
{ "key": "base_url", "secret": false, "initialValue": "https://dev.v-encore-lab.com", "currentValue": "https://dev.v-encore-lab.com" },
|
||||||
|
{ "key": "username", "secret": false, "initialValue": "admin", "currentValue": "admin" },
|
||||||
|
{ "key": "password", "secret": false, "initialValue": "admin", "currentValue": "admin" },
|
||||||
|
{ "key": "access_token", "secret": false, "initialValue": "", "currentValue": "" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"prod": {
|
||||||
|
"id": "3ckrklvkf27",
|
||||||
|
"v": 2,
|
||||||
|
"name": "PROD",
|
||||||
|
"variables": [
|
||||||
|
{ "key": "base_url", "secret": false, "initialValue": "https://v-encore-lab.com", "currentValue": "https://v-encore-lab.com" },
|
||||||
|
{ "key": "username", "secret": false, "initialValue": "admin", "currentValue": "admin" },
|
||||||
|
{ "key": "password", "secret": false, "initialValue": "admin", "currentValue": "admin" },
|
||||||
|
{ "key": "access_token", "secret": false, "initialValue": "", "currentValue": "" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user