Browse Source

Preparando lyrics

politica
Celestino Rey 1 year ago
parent
commit
d9804f4eb6
10 changed files with 133 additions and 84 deletions
  1. +1
    -0
      ReyMotaAppsDj/.dockerignore
  2. +1
    -1
      ReyMotaAppsDj/K8S/Makefile
  3. +2
    -2
      ReyMotaAppsDj/reymota/lyrics/forms.py
  4. +0
    -0
      ReyMotaAppsDj/reymota/lyrics/management/commands/__init__.py
  5. +23
    -0
      ReyMotaAppsDj/reymota/lyrics/management/commands/importa_album.py
  6. +23
    -0
      ReyMotaAppsDj/reymota/lyrics/management/commands/importa_artista.py
  7. +25
    -0
      ReyMotaAppsDj/reymota/lyrics/management/commands/importa_song.py
  8. +1
    -1
      ReyMotaAppsDj/reymota/lyrics/models.py
  9. +1
    -31
      ReyMotaAppsDj/reymota/lyrics/views.py
  10. +56
    -49
      ReyMotaAppsDj/reymota/templates/lyrics/lista_albumes.html

+ 1
- 0
ReyMotaAppsDj/.dockerignore View File

@ -2,3 +2,4 @@ Dockerfile
Makefile
volcadossql/
venv/
reymota/lyrics/management/

+ 1
- 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.9
export IMG_VERSION = 0.16
export IMG_NGINX_VERSION = 1.0
# limpia todo


+ 2
- 2
ReyMotaAppsDj/reymota/lyrics/forms.py View File

@ -19,8 +19,8 @@ class AlbumForm(forms.ModelForm):
model = Album
fields = ['name', 'artist', 'year', 'cover_image']
year = forms.DateField(
widget=forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}))
# year = forms.DateField(
# widget=forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}))
artist = forms.ModelChoiceField(
queryset=Artista.objects.all(),


+ 0
- 0
ReyMotaAppsDj/reymota/lyrics/management/commands/__init__.py View File


+ 23
- 0
ReyMotaAppsDj/reymota/lyrics/management/commands/importa_album.py View File

@ -0,0 +1,23 @@
from django.core.management.base import BaseCommand, CommandError
from lyrics.models import Album, Artista, Song
import csv
import argparse
from datetime import datetime
class Command(BaseCommand):
help = "Importa la lista de letras"
def add_arguments(self, parser):
parser.add_argument("fichero_csv", type=str, help='Ruta al fichero csv')
def handle(self, *args, **options):
fichero = options["fichero_csv"]
with open(fichero, 'r') as file:
reader = csv.DictReader(file)
for row in reader:
name = row['name'],
artist = row['artist'],
year = row['year'],
cover_image = row['cover_image']
print(name, ",", artist, ",", year, ",", cover_image)

+ 23
- 0
ReyMotaAppsDj/reymota/lyrics/management/commands/importa_artista.py View File

@ -0,0 +1,23 @@
from django.core.management.base import BaseCommand, CommandError
from lyrics.models import Album, Artista, Song
import csv
import argparse
from datetime import datetime
class Command(BaseCommand):
help = "Importa la lista de letras"
def add_arguments(self, parser):
parser.add_argument("fichero_csv", type=str, help='Ruta al fichero csv')
def handle(self, *args, **options):
fichero = options["fichero_csv"]
with open(fichero, 'r') as file:
reader = csv.DictReader(file)
for row in reader:
name = row['name'],
artist = row['artist'],
year = row['year'],
cover_image = row['cover_image']
print(name, ",", artist, ",", year, ",", cover_image)

+ 25
- 0
ReyMotaAppsDj/reymota/lyrics/management/commands/importa_song.py View File

@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand, CommandError
from lyrics.models import Album, Artista, Song
import csv
import argparse
from datetime import datetime
class Command(BaseCommand):
help = "Importa la lista de letras"
def add_arguments(self, parser):
parser.add_argument("fichero_csv", type=str, help='Ruta al fichero csv')
def handle(self, *args, **options):
fichero = options["fichero_csv"]
with open(fichero, 'r') as file:
reader = csv.DictReader(file)
for row in reader:
title = row['title'],
artist = row['artist'],
album = row['album'],
year = row['year'],
lyrics = row['lyrics']
pista = row['pista']
print(title, ",", artist, ",", album, ",", year, ",", pista)

+ 1
- 1
ReyMotaAppsDj/reymota/lyrics/models.py View File

@ -23,7 +23,7 @@ class Artista(models.Model):
class Album(models.Model):
name = models.CharField(max_length=200)
artist = models.ForeignKey(Artista, on_delete=models.CASCADE)
year = models.PositiveBigIntegerField(default=current_year(), validators=[MinValueValidator(1984), max_value_current_year])
year = models.PositiveBigIntegerField(default=current_year(), validators=[MinValueValidator(1945), max_value_current_year])
cover_image = models.ImageField(upload_to='cover_image/', blank=True, null=True) # Nuevo campo
def __str__(self):


+ 1
- 31
ReyMotaAppsDj/reymota/lyrics/views.py View File

@ -86,37 +86,7 @@ def nuevo_album(request):
if request.method == 'POST':
form = AlbumForm(request.POST, request.FILES)
if form.is_valid():
instancia = form.save(commit=False)
aplica_descuento = form.cleaned_data['aplica_descuento']
if aplica_descuento:
instancia.descuento = float(instancia.importe) * 0.03
else:
instancia.descuento = 0.0
instancia.importe = float(instancia.importe) - instancia.descuento
if instancia.litros > 0:
instancia.precioxlitro = round(instancia.importe / float(instancia.litros), 2)
else:
instancia.precioxlitro = 0
# lee todos los albumes del vehículo
# albumes = Albums.query.filter_by(artista_id=artista_id).all()
if Album.objects.filter(artista_id=instancia.artista):
albumes = Album.objects.filter(artista_id=instancia.artista).order_by('-fecha')[0]
instancia.kmsrecorridos = instancia.kms - albumes.kms
if instancia.kmsrecorridos > 0:
instancia.consumo = round(instancia.litros * 100 / instancia.kmsrecorridos, 2)
else:
instancia.kmsrecorridos = 0
instancia.consumo = 0
instancia.save()
form.save()
return redirect('lyrics:lista_albumes')
else:


+ 56
- 49
ReyMotaAppsDj/reymota/templates/lyrics/lista_albumes.html View File

@ -7,56 +7,63 @@
{% endblock menuapp %}
{% block content %}
<div class="container-xl">
<div class="row g-3 mb-4 align-items-center justify-content-between">
<div class="col-auto">
<h1 class="app-page-title mb-0">Álbumes</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 'lyrics:nuevo_album' %}">Añadir álbum</a>
</div>
</div><!--//row-->
</div><!--//table-utilities-->
</div><!--//col-auto-->
<div class="container-xl">
<div class="row g-3 mb-4 align-items-center justify-content-between">
<div class="col-auto">
<h1 class="app-page-title mb-0">Álbumes</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 'lyrics:nuevo_album' %}">Añadir álbum</a>
</div>
</div><!--//row-->
</div><!--//table-utilities-->
</div><!--//col-auto-->
<div class="app-card app-card-notification shadow-sm mb-4">
<div class="app-card-body p-4">
<table class="table app-table-hover mb-0 text-left">
<thead>
<tr>
<th class="cell">Fecha</th>
<th class="cell">Vehículo</th>
<th class="cell">Kilómetros</th>
<th class="cell">Litros</th>
<th class="cell">Importe</th>
<th class="cell">Descuento</th>
<th class="cell">Precio por litro</th>
<th class="cell">Kms recorridos</th>
<th class="cell">Consumo/100 kms</th>
</tr>
</thead>
{% for repostaje in repostajes %}
<nav id="orders-table-tab" class="orders-table-tab app-nav-tabs nav shadow-sm flex-column flex-sm-row mb-4">
<a class="flex-sm-fill text-sm-center nav-link" id="albumes-tab" data-bs-toggle="tab" href="#albumes" role="tab" aria-controls="albumes" aria-selected="false">Álbumes</a>
</nav>
<div class="tab-content" id="orders-table-tab-content">
<div class="tab-pane fade show active" id="albumes" role="tabpanel" aria-labelledby="albumes-tab">
<div class="app-card app-card-orders-table shadow-sm mb-5">
<div class="app-card-body">
<div class="table-responsive">
<table class="table app-table-hover mb-0 text-left">
<thead>
<tr>
<tbody>
<tr>
<td class="cell"><a href="{% url 'repostajes:detalle_repostaje' repostaje.id %}">{{ repostaje.fecha }}</a></td>
<td class="cell"><a href="{% url 'repostajes:detalle_vehiculo' repostaje.vehiculo.id %}">{{ repostaje.vehiculo.matricula }}</a></td>
<td class="cell">{{ repostaje.kms }}</td>
<td class="cell">{{ repostaje.litros }}</td>
<td class="cell">{{ repostaje.importe }} €</td>
<td class="cell">{{ repostaje.descuento }} €</td>
<td class="cell">{{ repostaje.precioxlitro }} €</td>
<td class="cell">{{ repostaje.kmsrecorridos }}</td>
<td class="cell">{{ repostaje.consumo }}</td>
</tr>
</tbody>
{% endfor %}
</table>
</div>
</div><!--//container-fluid-->
<th class="cell">Cover</th>
<th class="cell">Nombre</th>
<th class="cell">Artista</th>
<th class="cell">Año</th>
</tr>
</thead>
<tbody>
{% for album in albumes %}
<tr>
<td class="cell">
{% if album.cover_image %}
<img src="{{ album.cover_image.url }}" alt="{{ album.name }}" style="width:50px;height:50px;">
{% else %}
Sin imágen
{% endif %}
</td>
<td class="cell"><a href="{% url 'lyrics:detalle_album' album_id=album.id %}">{{ album.name }}</a></td>
<td class="cell">{{ album.artist }}</td>
<td class="cell">{{ album.year }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div><!--//table-responsive-->
</div><!--//app-card-body-->
</div><!--//app-card-->
</div><!--//tab-pane-->
</div><!--//tab-content-->
</div><!--//container-fluid-->
{% endblock %}

Loading…
Cancel
Save