Browse Source

Añado comando para importar vehiculos y reposajes

politica
Celestino Rey 10 months ago
parent
commit
72c3e39f54
4 changed files with 28 additions and 24 deletions
  1. +2
    -1
      ReyMotaAppsDj/K8S/Makefile
  2. +1
    -1
      ReyMotaAppsDj/K8S/env-prod-configmap.yaml
  3. +20
    -16
      ReyMotaAppsDj/reymota/repostajes/management/commands/importar_repostajes.py
  4. +5
    -6
      ReyMotaAppsDj/reymota/repostajes/management/commands/importar_vehiculos.py

+ 2
- 1
ReyMotaAppsDj/K8S/Makefile View File

@ -1,7 +1,7 @@
export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':')
#export REGISTRY=registry.cube.local
export REGISTRY=registry.reymota.es
export IMG_VERSION = 0.36
export IMG_VERSION = 0.45
export IMG_NGINX_VERSION = 1.0
# limpia todo
@ -27,6 +27,7 @@ install:
-envsubst < reymota-deployment.yaml |kubectl create -f -
-envsubst < nginx-deployment.yaml |kubectl create -f -
-kubectl create -f nginx-service.yaml
-kubectl create -f reymota-ingress.yaml
clean:
-envsubst < nginx-deployment.yaml |kubectl delete -f -


+ 1
- 1
ReyMotaAppsDj/K8S/env-prod-configmap.yaml View File

@ -3,7 +3,7 @@ data:
DEBUG: "False"
ENTORNO: "Producción"
DJANGO_ALLOWED_HOSTS: "reymota.rancher.my.org reymota.es vmcluster k8s-server localhost 127.0.0.1 [::1]"
CSRF_TRUSTED_ORIGINS: "https://reymota.es http://vmcluster http://reymota.rancher.my.org/ "
CSRF_TRUSTED_ORIGINS: "https://reymota.es http://vmcluster http://reymota.rancher.my.org/ http://localhost http://127.0.0.1"
SECRET_KEY: change_me
SQL_DATABASE: reymota
SQL_ENGINE: django.db.backends.postgresql


+ 20
- 16
ReyMotaAppsDj/reymota/repostajes/management/commands/importar_repostajes.py View File

@ -1,6 +1,6 @@
import json
from django.core.management.base import BaseCommand
from repostajes.models import Repostaje
from repostajes.models import Repostaje, Vehiculo
class Command(BaseCommand):
@ -25,21 +25,25 @@ class Command(BaseCommand):
repostajes_creados = 0
for repostaje_data in datos:
repostaje, creado = Repostaje.objects.get_or_create(
fecha=repostaje_data['fecha'],
defaults={
'kms': repostaje_data['kms'],
'litros': repostaje_data['litros'],
'descuento': repostaje_data['descuento'],
'importe': repostaje_data['importe'],
'precioxlitro': repostaje_data['precioxlitro'],
'kmsrecorridos': repostaje_data['kmsrecorridos'],
'consumo': repostaje_data['consumo'],
'vehiculo': repostaje_data['vehiculo']
}
)
if creado:
repostajes_creados += 1
try:
vehiculo = Vehiculo.objects.get(id=repostaje_data["vehiculo"])
creado = Repostaje.objects.create(
vehiculo_id=vehiculo.id,
fecha=repostaje_data['fecha'],
kms=repostaje_data['kms'],
litros=repostaje_data['litros'],
descuento=repostaje_data['descuento'],
importe=repostaje_data['importe'],
precioxlitro=repostaje_data['precioxlitro'],
kmsrecorridos=repostaje_data['kmsrecorridos'],
consumo=repostaje_data['consumo']
)
if creado:
repostajes_creados += 1
except Vehiculo.DoesNotExist:
self.stderr.write(self.style.ERROR(f"Vehiculo '{repostaje_data['vehiculo']}' no encontrado."))
self.stdout.write(self.style.SUCCESS(f'Se importaron {repostajes_creados} repostajes correctamente.'))


+ 5
- 6
ReyMotaAppsDj/reymota/repostajes/management/commands/importar_vehiculos.py View File

@ -25,13 +25,12 @@ class Command(BaseCommand):
vehiculos_creados = 0
for vehiculo_data in datos:
vehiculo, creado = Vehiculo.objects.get_or_create(
creado = Vehiculo.objects.create(
id=vehiculo_data['id'],
marca=vehiculo_data['marca'],
defaults={
'modelo': vehiculo_data['modelo'],
'matricula': vehiculo_data['matricula'],
'foto': vehiculo_data['foto']
}
modelo=vehiculo_data['modelo'],
matricula=vehiculo_data['matricula'],
foto=vehiculo_data['foto']
)
if creado:
vehiculos_creados += 1


Loading…
Cancel
Save