Browse Source

Cambio todo lo de repostajes por entrenadores

main
Celestino Rey 8 months ago
parent
commit
67634b092e
12 changed files with 74 additions and 28 deletions
  1. +4
    -3
      src/macrociclos/admin.py
  2. +47
    -0
      src/macrociclos/management/commands/importar_deportistas.py
  3. +6
    -13
      src/macrociclos/management/commands/importar_entrenadores.py
  4. +14
    -12
      src/macrociclos/management/commands/importar_macrociclos.py
  5. +3
    -0
      src/macrociclos/views.py
  6. +0
    -0
      src/templates/repostajes/_menu-entrenadores.html
  7. +0
    -0
      src/templates/repostajes/detalle_deportista.html
  8. +0
    -0
      src/templates/repostajes/detalle_entrenador.html
  9. +0
    -0
      src/templates/repostajes/form_deportista.html
  10. +0
    -0
      src/templates/repostajes/form_entrenador.html
  11. +0
    -0
      src/templates/repostajes/lista_deportistas.html
  12. +0
    -0
      src/templates/repostajes/lista_entrenadores.html

+ 4
- 3
src/macrociclos/admin.py View File

@ -3,7 +3,8 @@ from django.contrib import admin
# Register your models here.
from .models import Vehiculo, Repostaje
from .models import Entrenador, Deportista, Macrociclo
admin.site.register(Vehiculo)
admin.site.register(Repostaje)
admin.site.register(Entrenador)
admin.site.register(Deportista)
admin.site.register(Macrociclo)

+ 47
- 0
src/macrociclos/management/commands/importar_deportistas.py View File

@ -0,0 +1,47 @@
import json
from django.core.management.base import BaseCommand
from entrenadores.models import Deportista
class Command(BaseCommand):
help = "Importa deportistas desde un archivo JSON"
def add_arguments(self, parser):
parser.add_argument('archivo_json', type=str, help="Ruta del archivo JSON")
def handle(self, *args, **kwargs):
archivo_json = kwargs['archivo_json']
try:
with open(archivo_json, 'r', encoding='utf-8') as file:
datos = json.load(file)
self.stdout.write(self.style.WARNING(f"\nSe encontraron {len(datos)} deportistas en el archivo '{archivo_json}'."))
confirmar = input("¿Deseas continuar con la importación? (s/n): ").strip().lower()
if confirmar != 's':
self.stdout.write(self.style.ERROR("Importación cancelada."))
return
entrenadores_creados = 0
for entrenador_data in datos:
try:
deportista = Deportista.objects.get(matricula=entrenador_data["deportista_matricula"])
creado = Deportista.objects.create(
deportista=deportista,
nombre=entrenador_data['nombre'],
entrenador=entrenador_data['entrenador']
)
if creado:
entrenadores_creados += 1
except Deportista.DoesNotExist:
self.stderr.write(self.style.ERROR(f"Deportista con matrícula '{entrenador_data['deportista_matricula']}' no encontrado."))
self.stdout.write(self.style.SUCCESS(f'Se importaron {entrenadores_creados} entrenadores correctamente.'))
except FileNotFoundError:
self.stderr.write(self.style.ERROR(f"El archivo {archivo_json} no se encontró."))
except json.JSONDecodeError:
self.stderr.write(self.style.ERROR("Error al leer el archivo JSON. Asegúrate de que el formato sea correcto."))

src/macrociclos/management/commands/importar_repostajes.py → src/macrociclos/management/commands/importar_entrenadores.py View File

@ -1,6 +1,6 @@
import json
from django.core.management.base import BaseCommand
from entrenadores.models import Entrenador, Macrociclo
from entrenadores.models import Entrenador
class Command(BaseCommand):
@ -26,24 +26,17 @@ class Command(BaseCommand):
entrenadores_creados = 0
for entrenador_data in datos:
try:
macrociclo = Macrociclo.objects.get(matricula=entrenador_data["macrociclo_matricula"])
entrenador = Entrenador.objects.get(matricula=entrenador_data["entrenador_matricula"])
creado = Entrenador.objects.create(
macrociclo=macrociclo,
fecha=entrenador_data['fecha'],
kms=entrenador_data['kms'],
litros=entrenador_data['litros'],
descuento=entrenador_data['descuento'],
importe=entrenador_data['importe'],
precioxlitro=entrenador_data['precioxlitro'],
kmsrecorridos=entrenador_data['kmsrecorridos'],
consumo=entrenador_data['consumo']
entrenador=entrenador,
nombre=entrenador_data['nombre']
)
if creado:
entrenadores_creados += 1
except Macrociclo.DoesNotExist:
self.stderr.write(self.style.ERROR(f"Macrociclo con matrícula '{entrenador_data['macrociclo_matricula']}' no encontrado."))
except Entrenador.DoesNotExist:
self.stderr.write(self.style.ERROR(f"Entrenador con matrícula '{entrenador_data['entrenador_matricula']}' no encontrado."))
self.stdout.write(self.style.SUCCESS(f'Se importaron {entrenadores_creados} entrenadores correctamente.'))

src/macrociclos/management/commands/importar_vehiculos.py → src/macrociclos/management/commands/importar_macrociclos.py View File

@ -1,10 +1,10 @@
import json
from django.core.management.base import BaseCommand
from repostajes.models import Vehiculo
from macrociclos.models import Macrociclo
class Command(BaseCommand):
help = "Importa vehiculos desde un archivo JSON"
help = "Importa macrociclos desde un archivo JSON"
def add_arguments(self, parser):
parser.add_argument('archivo_json', type=str, help="Ruta del archivo JSON")
@ -16,25 +16,27 @@ class Command(BaseCommand):
with open(archivo_json, 'r', encoding='utf-8') as file:
datos = json.load(file)
self.stdout.write(self.style.WARNING(f"\nSe encontraron {len(datos)} vehiculos en el archivo '{archivo_json}'."))
self.stdout.write(self.style.WARNING(f"\nSe encontraron {len(datos)} macrociclos en el archivo '{archivo_json}'."))
confirmar = input("¿Deseas continuar con la importación? (s/n): ").strip().lower()
if confirmar != 's':
self.stdout.write(self.style.ERROR("Importación cancelada."))
return
vehiculos_creados = 0
for vehiculo_data in datos:
creado = Vehiculo.objects.create(
marca=vehiculo_data['marca'],
modelo=vehiculo_data['modelo'],
matricula=vehiculo_data['matricula'],
foto=vehiculo_data['foto']
macrociclos_creados = 0
for macrociclo_data in datos:
creado = Macrociclo.objects.create(
nombre=macrociclo_data['nombre'],
tipo=macrociclo_data['tipo'],
desde=macrociclo_data['desde'],
hasta=macrociclo_data['hasta']
deportista=macrociclo_data['deportista']
entrenador=macrociclo_data['entrenador']
)
if creado:
vehiculos_creados += 1
macrociclos_creados += 1
self.stdout.write(self.style.SUCCESS(f'Se importaron {vehiculos_creados} vehiculos correctamente.'))
self.stdout.write(self.style.SUCCESS(f'Se importaron {macrociclos_creados} macrociclos correctamente.'))
except FileNotFoundError:
self.stderr.write(self.style.ERROR(f"El archivo {archivo_json} no se encontró."))

+ 3
- 0
src/macrociclos/views.py View File

@ -133,6 +133,9 @@ def eliminar_entrenador(request, entrenador_id):
entrenador.delete()
return redirect('macrociclos:lista_deportistas')
#
# API
#
@api_view(['GET'])
def api_lista_entrenadores(request):


src/templates/repostajes/_menu-repostajes.html → src/templates/repostajes/_menu-entrenadores.html View File


src/templates/repostajes/detalle_repostaje.html → src/templates/repostajes/detalle_deportista.html View File


src/templates/repostajes/detalle_vehiculo.html → src/templates/repostajes/detalle_entrenador.html View File


src/templates/repostajes/form_repostaje.html → src/templates/repostajes/form_deportista.html View File


src/templates/repostajes/form_vehiculo.html → src/templates/repostajes/form_entrenador.html View File


src/templates/repostajes/lista_repostajes.html → src/templates/repostajes/lista_deportistas.html View File


src/templates/repostajes/lista_vehiculos.html → src/templates/repostajes/lista_entrenadores.html View File


Loading…
Cancel
Save