Browse Source

Listo para empezar a probar

politica
Celestino Rey 1 year ago
parent
commit
6d82ea77e4
27 changed files with 169 additions and 109 deletions
  1. +1
    -1
      RepostajesDj/Dockerfile
  2. +1
    -1
      RepostajesDj/K8S/db-deployment.yaml
  3. +1
    -1
      RepostajesDj/K8S/db-service.yaml
  4. +1
    -1
      RepostajesDj/K8S/entra.sh
  5. +1
    -1
      RepostajesDj/K8S/entraPsql.sh
  6. +4
    -4
      RepostajesDj/K8S/env-prod-configmap.yaml
  7. +2
    -2
      RepostajesDj/K8S/env-prod-db-configmap.yaml
  8. +1
    -1
      RepostajesDj/K8S/namespace.yaml
  9. +7
    -7
      RepostajesDj/K8S/nginx-deployment.yaml
  10. +1
    -1
      RepostajesDj/K8S/nginx-service.yaml
  11. +1
    -1
      RepostajesDj/K8S/postgres-data-persistentvolumeclaim.yaml
  12. +16
    -16
      RepostajesDj/K8S/pv-local-vehiculos.yaml
  13. +1
    -1
      RepostajesDj/K8S/reg-secret.yaml
  14. +1
    -1
      RepostajesDj/K8S/static-volume-persistentvolumeclaim.yaml
  15. +20
    -20
      RepostajesDj/K8S/vehiculos-deployment.yaml
  16. +6
    -6
      RepostajesDj/K8S/vehiculos-prod-persistentvolumeclaim.yaml
  17. +1
    -1
      RepostajesDj/K8S/verImg.sh
  18. +2
    -2
      RepostajesDj/Makefile
  19. +2
    -2
      RepostajesDj/nginx/Makefile
  20. +5
    -5
      RepostajesDj/nginx/nginx.conf
  21. +5
    -5
      RepostajesDj/vehiculos/repostajes/templates/_cabecera.html
  22. +1
    -1
      RepostajesDj/vehiculos/repostajes/templates/_head.html
  23. +4
    -14
      RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_repostaje.html
  24. +1
    -1
      RepostajesDj/vehiculos/repostajes/templates/repostajes/form_repostaje.html
  25. +1
    -1
      RepostajesDj/vehiculos/repostajes/templates/repostajes/form_vehiculo.html
  26. +7
    -12
      RepostajesDj/vehiculos/repostajes/templates/repostajes/lista_repostajes.html
  27. +75
    -0
      RepostajesDj/vehiculos/repostajes/views.py

+ 1
- 1
RepostajesDj/Dockerfile View File

@ -67,7 +67,7 @@ COPY . $APP_HOME
# change to the app user
#USER app
WORKDIR $APP_HOME/biblioteca
WORKDIR $APP_HOME/vehiculos
# run entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]

+ 1
- 1
RepostajesDj/K8S/db-deployment.yaml View File

@ -7,7 +7,7 @@ metadata:
labels:
io.kompose.service: db
name: db
namespace: libros
namespace: vehiculos
spec:
replicas: 1
selector:


+ 1
- 1
RepostajesDj/K8S/db-service.yaml View File

@ -7,7 +7,7 @@ metadata:
labels:
io.kompose.service: db
name: db
namespace: libros
namespace: vehiculos
spec:
ports:
- name: "5432"


+ 1
- 1
RepostajesDj/K8S/entra.sh View File

@ -1 +1 @@
kubectl -n libros exec -ti deployment.apps/libros -- /bin/bash
kubectl -n vehiculos exec -ti deployment.apps/vehiculos -- /bin/bash

+ 1
- 1
RepostajesDj/K8S/entraPsql.sh View File

@ -1 +1 @@
kubectl -n libros exec -ti deployment.apps/db -- psql --username=creylopez --dbname=libros
kubectl -n vehiculos exec -ti deployment.apps/db -- psql --username=creylopez --dbname=vehiculos

+ 4
- 4
RepostajesDj/K8S/env-prod-configmap.yaml View File

@ -1,10 +1,10 @@
apiVersion: v1
data:
DEBUG: "0"
DJANGO_ALLOWED_HOSTS: "libros.reymota.es k8s-server localhost 127.0.0.1 [::1]"
CSRF_TRUSTED_ORIGINS: "https://libros.reymota.es"
DJANGO_ALLOWED_HOSTS: "vehiculos.reymota.es k8s-server localhost 127.0.0.1 [::1]"
CSRF_TRUSTED_ORIGINS: "https://vehiculos.reymota.es"
SECRET_KEY: change_me
SQL_DATABASE: libros
SQL_DATABASE: vehiculos
SQL_ENGINE: django.db.backends.postgresql
SQL_HOST: db
SQL_PASSWORD: Dsa-0213
@ -16,4 +16,4 @@ metadata:
labels:
io.kompose.service: web-env-prod
name: env-prod
namespace: libros
namespace: vehiculos

+ 2
- 2
RepostajesDj/K8S/env-prod-db-configmap.yaml View File

@ -1,6 +1,6 @@
apiVersion: v1
data:
POSTGRES_DB: libros
POSTGRES_DB: vehiculos
POSTGRES_PASSWORD: Dsa-0213
POSTGRES_USER: creylopez
kind: ConfigMap
@ -8,4 +8,4 @@ metadata:
labels:
io.kompose.service: db-env-prod-db
name: env-prod-db
namespace: libros
namespace: vehiculos

+ 1
- 1
RepostajesDj/K8S/namespace.yaml View File

@ -4,4 +4,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: libros
name: vehiculos

+ 7
- 7
RepostajesDj/K8S/nginx-deployment.yaml View File

@ -7,7 +7,7 @@ metadata:
labels:
io.kompose.service: nginx
name: nginx
namespace: libros
namespace: vehiculos
spec:
replicas: 1
selector:
@ -24,16 +24,16 @@ spec:
io.kompose.service: nginx
spec:
containers:
- image: registry.reymota.es/nginx-libros-$ARQUITECTURA:$IMG_NGINX_VERSION
- image: registry.reymota.es/nginx-vehiculos-$ARQUITECTURA:$IMG_NGINX_VERSION
name: nginx
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- mountPath: /app/biblioteca/staticfiles
- mountPath: /app/vehiculos/staticfiles
name: static-volume
- mountPath: /app/biblioteca/mediafiles
name: libros-media
- mountPath: /app/vehiculos/mediafiles
name: vehiculos-media
imagePullSecrets:
- name: myregistrykey
restartPolicy: Always
@ -41,6 +41,6 @@ spec:
- name: static-volume
persistentVolumeClaim:
claimName: static-volume
- name: libros-media
- name: vehiculos-media
persistentVolumeClaim:
claimName: libros-media
claimName: vehiculos-media

+ 1
- 1
RepostajesDj/K8S/nginx-service.yaml View File

@ -7,7 +7,7 @@ metadata:
labels:
io.kompose.service: nginx
name: nginx
namespace: libros
namespace: vehiculos
spec:
type: NodePort
ports:


+ 1
- 1
RepostajesDj/K8S/postgres-data-persistentvolumeclaim.yaml View File

@ -4,7 +4,7 @@ metadata:
labels:
io.kompose.service: postgres-data
name: postgres-data
namespace: libros
namespace: vehiculos
spec:
accessModes:
- ReadWriteOnce


RepostajesDj/K8S/pv-local-libros.yaml → RepostajesDj/K8S/pv-local-vehiculos.yaml View File

@ -1,59 +1,59 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: libros-media-folder
namespace: libros
name: vehiculos-media-folder
namespace: vehiculos
labels:
app: libros
app: vehiculos
spec:
capacity:
storage: 100Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/Externo/libros/media"
path: "/mnt/Externo/vehiculos/media"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: libros-migrations-folder
namespace: libros
name: vehiculos-migrations-folder
namespace: vehiculos
labels:
app: libros
app: vehiculos
spec:
capacity:
storage: 50Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/Externo/libros/migrations"
path: "/mnt/Externo/vehiculos/migrations"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: libros-static-folder
namespace: libros
name: vehiculos-static-folder
namespace: vehiculos
labels:
app: libros
app: vehiculos
spec:
capacity:
storage: 70Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/Externo/libros/static"
path: "/mnt/Externo/vehiculos/static"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: libros-pg-folder
namespace: libros
name: vehiculos-pg-folder
namespace: vehiculos
labels:
app: libros
app: vehiculos
spec:
capacity:
storage: 200Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/Externo/libros/pg"
path: "/mnt/Externo/vehiculos/pg"

+ 1
- 1
RepostajesDj/K8S/reg-secret.yaml View File

@ -2,7 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: myregistrykey
namespace: libros
namespace: vehiculos
data:
.dockerconfigjson: ewoJImF1dGhzIjogewoJCSJyZWdpc3RyeS5yZXltb3RhLmVzIjogewoJCQkiYXV0aCI6ICJZM0psZVd4dmNHVjZPbEpsZVMweE1UYzIiCgkJfQoJfQp9
type: kubernetes.io/dockerconfigjson

+ 1
- 1
RepostajesDj/K8S/static-volume-persistentvolumeclaim.yaml View File

@ -4,7 +4,7 @@ metadata:
labels:
io.kompose.service: static-volume
name: static-volume
namespace: libros
namespace: vehiculos
spec:
accessModes:
- ReadWriteOnce


RepostajesDj/K8S/libros-deployment.yaml → RepostajesDj/K8S/vehiculos-deployment.yaml View File

@ -1,43 +1,43 @@
apiVersion: v1
kind: Service
metadata:
name: libros
namespace: libros
name: vehiculos
namespace: vehiculos
spec:
ports:
- name: "8000"
port: 8000
targetPort: 8000
selector:
app: libros
app: vehiculos
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: libros
namespace: libros
name: vehiculos
namespace: vehiculos
labels:
app: libros
app: vehiculos
spec:
replicas: 1
selector:
matchLabels:
app: libros
app: vehiculos
strategy:
type: Recreate
template:
metadata:
labels:
app: libros
app: vehiculos
spec:
containers:
- args:
- gunicorn
- biblioteca.wsgi:application
- vehiculos.wsgi:application
- --bind
- 0.0.0.0:8000
name: libros
image: registry.reymota.es/libros-$ARQUITECTURA:$IMG_VERSION
name: vehiculos
image: registry.reymota.es/vehiculos-$ARQUITECTURA:$IMG_VERSION
env:
- name: VERSION
value: "$IMG_VERSION"
@ -102,22 +102,22 @@ spec:
- containerPort: 8000
protocol: TCP
volumeMounts:
- mountPath: /app/biblioteca/mediafiles
name: libros-media
- mountPath: /app/gestion/migrations
name: libros-migrations
- mountPath: /app/biblioteca/staticfiles
- mountPath: /app/vehiculos/mediafiles
name: vehiculos-media
- mountPath: /app/repostajes/migrations
name: vehiculos-migrations
- mountPath: /app/vehiculos/staticfiles
name: static-volume
imagePullSecrets:
- name: myregistrykey
restartPolicy: Always
volumes:
- name: libros-media
- name: vehiculos-media
persistentVolumeClaim:
claimName: libros-media
- name: libros-migrations
claimName: vehiculos-media
- name: vehiculos-migrations
persistentVolumeClaim:
claimName: libros-migrations
claimName: vehiculos-migrations
- name: static-volume
persistentVolumeClaim:
claimName: static-volume

RepostajesDj/K8S/libros-prod-persistentvolumeclaim.yaml → RepostajesDj/K8S/vehiculos-prod-persistentvolumeclaim.yaml View File

@ -3,9 +3,9 @@ kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: libros-media
name: libros-media
namespace: libros
io.kompose.service: vehiculos-media
name: vehiculos-media
namespace: vehiculos
spec:
accessModes:
- ReadWriteOnce
@ -19,9 +19,9 @@ kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: libros-migrations
name: libros-migrations
namespace: libros
io.kompose.service: vehiculos-migrations
name: vehiculos-migrations
namespace: vehiculos
spec:
accessModes:
- ReadWriteOnce

+ 1
- 1
RepostajesDj/K8S/verImg.sh View File

@ -1 +1 @@
docker run -it registry.reymota.es/libros:1.19 bash
docker run -it registry.reymota.es/vehiculos:1.19 bash

+ 2
- 2
RepostajesDj/Makefile View File

@ -2,7 +2,7 @@ install:
echo "Creando imagen con version ${IMG_VERSION}"
docker build --no-cache -t registry.reymota.es/libros-${ARQUITECTURA}:${IMG_VERSION} .
docker push registry.reymota.es/libros-${ARQUITECTURA}:${IMG_VERSION}
docker build --no-cache -t registry.reymota.es/vehiculos-${ARQUITECTURA}:${IMG_VERSION} .
docker push registry.reymota.es/vehiculos-${ARQUITECTURA}:${IMG_VERSION}

+ 2
- 2
RepostajesDj/nginx/Makefile View File

@ -2,7 +2,7 @@ install:
echo "Creando imagen con version ${IMG_NGINX_VERSION} para la arquitectura ${ARQUITECTURA}"
docker build --no-cache -t registry.reymota.es/nginx-libros-${ARQUITECTURA}:${IMG_NGINX_VERSION} .
docker push registry.reymota.es/nginx-libros-${ARQUITECTURA}:${IMG_NGINX_VERSION}
docker build --no-cache -t registry.reymota.es/nginx-vehiculos-${ARQUITECTURA}:${IMG_NGINX_VERSION} .
docker push registry.reymota.es/nginx-vehiculos-${ARQUITECTURA}:${IMG_NGINX_VERSION}

+ 5
- 5
RepostajesDj/nginx/nginx.conf View File

@ -1,5 +1,5 @@
upstream libros {
server libros:8000;
upstream vehiculos {
server vehiculos:8000;
}
server {
@ -7,7 +7,7 @@ server {
listen 80;
location / {
proxy_pass http://libros;
proxy_pass http://vehiculos;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
@ -15,11 +15,11 @@ server {
}
location /static/ {
alias /app/biblioteca/staticfiles/;
alias /app/vehiculos/staticfiles/;
}
location /media/ {
alias /app/biblioteca/mediafiles/;
alias /app/vehiculos/mediafiles/;
}
}

+ 5
- 5
RepostajesDj/vehiculos/repostajes/templates/_cabecera.html View File

@ -77,7 +77,7 @@
<li class="nav-item">
<!--//Bootstrap Icons: https://icons.getbootstrap.com/ -->
<a class="nav-link" href="{% url 'lista_libros' %}">
<a class="nav-link" href="{% url 'lista_repostajes' %}">
<span class="nav-icon">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-card-list" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M14.5 3h-13a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5h13a.5.5 0 0 0 .5-.5v-9a.5.5 0 0 0-.5-.5zm-13-1A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-13z"/>
@ -87,13 +87,13 @@
<circle cx="3.5" cy="10.5" r=".5"/>
</svg>
</span>
<span class="nav-link-text">Libros</span>
<span class="nav-link-text">Repostajes</span>
</a><!--//nav-link-->
</li><!--//nav-item-->
<li class="nav-item">
<!--//Bootstrap Icons: https://icons.getbootstrap.com/ -->
<a class="nav-link" href="{% url 'lista_autores' %}">
<a class="nav-link" href="{% url 'lista_vehiculos' %}">
<span class="nav-icon">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-card-list" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M14.5 3h-13a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5h13a.5.5 0 0 0 .5-.5v-9a.5.5 0 0 0-.5-.5zm-13-1A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-13z"/>
@ -128,8 +128,8 @@
</a><!--//nav-link-->
<div id="submenu-1" class="collapse submenu submenu-1" data-bs-parent="#menu-accordion">
<ul class="submenu-list list-unstyled">
<li class="submenu-item"><a class="submenu-link" href="{% url 'nuevo_libro' %}">Libro</a></li>
<li class="submenu-item"><a class="submenu-link" href="{% url 'nuevo_autor' %}">Autor</a></li>
<li class="submenu-item"><a class="submenu-link" href="{% url 'nuevo_repostaje' %}">Repostajes</a></li>
<li class="submenu-item"><a class="submenu-link" href="{% url 'nuevo_vehiculo' %}">Vehículo</a></li>
</ul>
</div>
</li><!--//nav-item-->


+ 1
- 1
RepostajesDj/vehiculos/repostajes/templates/_head.html View File

@ -3,7 +3,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Biblioteca de libros</title>
<title>Registro de vehículos y sus repostajes</title>
<!-- Meta -->
<meta charset="utf-8">


+ 4
- 14
RepostajesDj/vehiculos/repostajes/templates/repostajes/detalle_repostaje.html View File

@ -6,25 +6,15 @@
<div class="app-card app-card-notification shadow-sm mb-4">
<div class="app-card-header px-4 py-3">
<div class="row g-3 align-items-center">
<div class="col-12 col-lg-auto text-center text-lg-start">
{% if libro.portada %}
<p><img src="{{ libro.portada.url }}" alt="{{ libro.titulo }}" style="width:200px;height:200px;"></p>
{% else %}
<p>No hay imágen disponible</p>
{% endif %}
{% if libro.archivo %}
<p><a href="{{ libro.archivo.url }}">Descargar</a></p>
{% endif %}
</div><!--//col-->
<div class="col-12 col-lg-auto text-center text-lg-start">
<h4 class="notification-title mb-1">{{ libro.titulo }}</h4>
<h4 class="notification-title mb-1">{{ repostaje.fecha }}</h4>
<ul class="notification-meta list-inline mb-0">
<li class="list-inline-item">{{ libro.autor.nombre }}</li>
<li class="list-inline-item">{{ repostaje.vehiculo.matricula }}</li>
<li class="list-inline-item">|</li>
<li class="list-inline-item">{{ libro.fecha_publicacion }}</li>
<li class="list-inline-item">{{ repostaje.kms }}</li>
<li class="list-inline-item">|</li>
<li class="list-inline-item"><a href="{% url 'detalle_autor' libro.autor_id %}">{{ libro.autor.nombre }}</a></li>
<li class="list-inline-item"><a href="{% url 'detalle_vehiculo' repostaje.vehiculo_id %}">{{ repostaje.vehiculo.nombre }}</a></li>
</ul>
</div><!--//col-->
</tr>


+ 1
- 1
RepostajesDj/vehiculos/repostajes/templates/repostajes/form_repostaje.html View File

@ -2,7 +2,7 @@
{% block content %}
<div class="column is-4 is-offset-4">
<h3>{% if form.instance.pk %}Editar Libro{% else %}Nuevo Libro{% endif %}</h3>
<h3>{% if form.instance.pk %}Editar repostaje{% else %}Nuevo repostaje{% endif %}</h3>
<div class="box">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}


+ 1
- 1
RepostajesDj/vehiculos/repostajes/templates/repostajes/form_vehiculo.html View File

@ -3,7 +3,7 @@
{% block content %}
<div class="column is-4 is-offset-4">
<h3>{% if form.instance.pk %}Editar Autor{% else %}Nuevo Autor{% endif %}</h3>
<h3>{% if form.instance.pk %}Editar vehículo{% else %}Nuevo vehículo{% endif %}</h3>
<div class="box">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}


+ 7
- 12
RepostajesDj/vehiculos/repostajes/templates/repostajes/lista_repostajes.html View File

@ -6,33 +6,28 @@
<div class="row g-3 mb-4 align-items-center justify-content-between">
<div class="col-auto">
<h1 class="app-page-title mb-0">Libros</h1>
<h1 class="app-page-title mb-0">Repostajes</h1>
</div>
</div><!--//row-->
<div class="col-auto">
<div class="page-utilities">
<div class="row g-4 justify-content-start justify-content-md-end align-items-center">
<div class="col-auto">
<a class="btn app-btn-primary" href="{% url 'nuevo_libro' %}">Añadir libro</a>
<a class="btn app-btn-primary" href="{% url 'nuevo_repostaje' %}">Añadir repostaje</a>
</div>
</div><!--//row-->
</div><!--//table-utilities-->
</div><!--//col-auto-->
<div class="row g-4">
{% for libro in libros %}
{% for repostaje in repostajes %}
<div class="col-6 col-md-4 col-xl-3 col-xxl-2">
<div class="app-card app-card-doc shadow-sm h-100">
<div class="app-card-body p-3 has-card-actions">
{% if libro.portada %}
<a><img src="{{ libro.portada.url }}" alt="{{ libro.titulo }}," style="width:50px;height:50px;"></a>
{% else %}
Sin imágen
{% endif %}
<h4 class="app-doc-title truncate mb-0"><a href="{% url 'detalle_libro' libro.id %}">{{ libro.titulo }}</a></h4>
<h4 class="app-doc-title truncate mb-0"><a href="{% url 'detalle_repostaje' repostaje.id %}">{{ repostaje.fecha }}</a></h4>
<div class="app-doc-meta">
<ul class="list-unstyled mb-0">
<li><span class="text-muted">Autor: </span><a href="{% url 'detalle_autor' libro.autor.id %}">{{ libro.autor.nombre }}</a></li>
<li><span class="text-muted">Vehiculo: </span><a href="{% url 'detalle_vehiculo' repostaje.vehiculo.id %}">{{ repostaje.vehiculo.matricula }}</a></li>
</ul>
</div><!--//app-doc-meta-->
@ -44,11 +39,11 @@
</svg>
</div><!--//dropdown-toggle-->
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="{% url 'editar_libro' libro.id %}"><svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pencil me-2" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<li><a class="dropdown-item" href="{% url 'editar_repostaje' repostaje.id %}"><svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pencil me-2" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5L13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175l-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/>
</svg>Editar</a></li>
<li><a class="dropdown-item" href="{{ libro.archivo.url }}"><svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-download me-2" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<li><a class="dropdown-item" href="{{ repostaje.archivo.url }}"><svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-download me-2" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/>
<path fill-rule="evenodd" d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/>
</svg>Descargar</a></li>


+ 75
- 0
RepostajesDj/vehiculos/repostajes/views.py View File

@ -4,6 +4,7 @@ from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from .models import Vehiculo, Repostaje
from .forms import VehiculoForm, RepostajeForm
@login_required
def principal(request):
@ -27,3 +28,77 @@ def detalle_vehiculo(request, vehiculo_id):
return render(request, 'repostajes/detalle_vehiculo.html', {'vehiculo': vehiculo, 'libros': libros})
@login_required
def nuevo_vehiculo(request):
if request.method == 'POST':
form = VehiculoForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('lista_vehiculoes')
else:
form = VehiculoForm()
return render(request, 'repostajes/form_vehiculo.html', {'form': form})
@login_required
def editar_vehiculo(request, vehiculo_id):
vehiculo = get_object_or_404(Vehiculo, pk=vehiculo_id)
if request.method == 'POST':
form = VehiculoForm(request.POST, request.FILES, instance=vehiculo)
if form.is_valid():
form.save()
return redirect('lista_vehiculoes')
else:
form = VehiculoForm(instance=vehiculo)
return render(request, 'repostajes/form_vehiculo.html', {'form': form})
@login_required
def eliminar_vehiculo(request, vehiculo_id):
vehiculo = get_object_or_404(Vehiculo, pk=vehiculo_id)
vehiculo.delete()
return redirect('lista_vehiculoes')
# Vistas para los libros
@login_required
def lista_libros(request):
libros = Repostaje.objects.all()
return render(request, 'repostajes/lista_libros.html', {'libros': libros})
@login_required
def detalle_libro(request, libro_id):
libro = get_object_or_404(Repostaje, pk=libro_id)
return render(request, 'repostajes/detalle_libro.html', {'libro': libro})
@login_required
def nuevo_libro(request):
if request.method == 'POST':
form = RepostajeForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('lista_libros')
else:
form = RepostajeForm()
return render(request, 'repostajes/form_libro.html', {'form': form})
@login_required
def editar_libro(request, libro_id):
libro = get_object_or_404(Repostaje, pk=libro_id)
if request.method == 'POST':
form = RepostajeForm(request.POST, request.FILES, instance=libro)
if form.is_valid():
form.save()
return redirect('lista_libros')
else:
form = RepostajeForm(instance=libro)
return render(request, 'repostajes/form_libro.html', {'form': form})
@login_required
def eliminar_libro(request, libro_id):
libro = get_object_or_404(Repostaje, pk=libro_id)
libro.delete()
return redirect('lista_libros')

Loading…
Cancel
Save