Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/AC42027/Backend-produccion/llms.txt

Use this file to discover all available pages before exploring further.

The Inspecciones Técnicas backend is a Django REST API that runs on Python 3.13 and connects to a MySQL database. This guide walks you through cloning the repository, installing dependencies, configuring your environment, and making your first authenticated request against a live server.
1

Clone the repository

Clone the backend repository and enter the project directory:
git clone https://github.com/AC42027/Backend-produccion.git
cd Backend-produccion
2

Create and activate a virtual environment

Create an isolated Python environment so that project dependencies do not conflict with system packages:
python -m venv venv
venv\Scripts\activate
3

Install dependencies

Install all required packages from requirements.txt:
pip install -r requirements.txt
Key packages installed include Django 5.2, Django REST Framework, PyMySQL, ldap3, python-decouple, django-cors-headers, and Waitress.
4

Create the .env file

The backend reads all sensitive configuration from a .env file in the project root. Create this file before running migrations or starting the server.See Configuration for a full reference of every variable. A minimal working example:
.env
SECRET_KEY=your-secret-django-key-here
DEBUG=False
ALLOWED_HOSTS=localhost,127.0.0.1
CSRF_TRUSTED_ORIGINS=http://localhost:3010

MYSQL_DATABASE=inspecciones
MYSQL_USER=your_db_user
MYSQL_PASSWORD=your_db_password
MYSQL_HOST=your_db_host
MYSQL_PORT=3306

LDAP_SERVER=your_ldap_server
LDAP_DOMAIN=miempresa.local

CORS_ALLOW_ALL_ORIGINS=False
CORS_ALLOWED_ORIGINS=http://localhost:3010
Never commit .env to version control. The project’s .gitignore already excludes it, but verify this before pushing.
5

Run database migrations

Apply Django’s migrations to create the required tables in your MySQL database:
python manage.py makemigrations
python manage.py migrate
Run makemigrations only when starting from a fresh clone or after model changes. For an existing database with the schema already applied, migrate alone is sufficient.
6

Start the development server

For local development, use Django’s built-in server:
python manage.py runserver
The API is available at http://localhost:8000.For production on Windows, use Waitress instead:
python run_waitress.py
Waitress serves the application on http://0.0.0.0:8080.

Make your first API requests

With the server running, authenticate with your LDAP credentials and then call a data endpoint. The examples below use port 8080 (Waitress/production). If you are running the Django dev server, replace 8080 with 8000.

Step 1: Authenticate via LDAP

Send your corporate username and password to /api/login-ldap/. A successful response sets a session cookie that you must include in subsequent requests.
curl -c cookies.txt -X POST http://localhost:8080/api/login-ldap/ \
  -H "Content-Type: application/json" \
  -d '{"username": "ac17157", "password": "your-password"}'
A successful response returns HTTP 200 with your user details:
{
  "status": "ok",
  "message": "Login exitoso",
  "first_name": "Juan",
  "last_name": "Pérez"
}

Step 2: Fetch the equipment list

Use the saved session cookie to call a protected endpoint:
curl -b cookies.txt http://localhost:8080/api/equipos/
The response returns the list of registered equipment:
[
  {
    "id": 1,
    "nombre": "Compresor A1",
    "ubicacion": "Planta Norte",
    "categoria": "Compresores",
    "categoria_id": 3,
    "zona": "Zona 1",
    "zona_id": 2,
    "area": "Producción",
    "area_id": 1,
    "division": "División Norte",
    "division_id": 1,
    "owner": "Juan Pérez"
  }
]
Session cookies expire after one hour of inactivity. The server extends the session automatically on each request while you remain active. Re-authenticate if you receive a 401 response.

Available endpoints

The following routes are registered in the API:
MethodPathDescription
POST/api/login-ldap/Authenticate with LDAP credentials
GET/api/logout/End the current session
GET/api/equipos/List all equipment
GET/api/equipo/<id>/Get a single equipment record
GET/api/divisiones/List divisions
GET/api/areas/List areas
GET/api/zonas/List zones
GET/api/categorias/List inspection categories
GET/api/preguntas/<category>/Get questions for a category
POST/api/guardar/Submit a completed inspection
GET/api/asignaciones/List weekly technician assignments
GET/api/dashboard/inspecciones/Retrieve all inspections for the dashboard
Access to most endpoints is restricted to requests from authorized IP ranges or registered hostnames. See IP Restrictions for the full policy. The dashboard endpoint (/api/dashboard/inspecciones/) is exempt from IP restrictions.

Build docs developers (and LLMs) love