Browse Source

Incluyo importador de canciones como comando

politica
Celestino Rey 1 year ago
parent
commit
0f312ec768
5 changed files with 42 additions and 13 deletions
  1. +1
    -1
      ReyMotaAppsDj/K8S/Makefile.local
  2. +1
    -0
      ReyMotaAppsDj/requirements.txt
  3. +11
    -10
      ReyMotaAppsDj/reymota/lyrics/management/commands/importa_song.py
  4. +3
    -1
      ReyMotaAppsDj/reymota/lyrics/views.py
  5. +26
    -1
      ReyMotaAppsDj/reymota/templates/lyrics/detalle_album.html

+ 1
- 1
ReyMotaAppsDj/K8S/Makefile.local View File

@ -2,7 +2,7 @@ export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':')
export REGISTRY=localhost:30500 export REGISTRY=localhost:30500
#export REGISTRY=registry.reymota.es #export REGISTRY=registry.reymota.es
export IMG_VERSION = 0.44
export IMG_VERSION = 0.46
export IMG_NGINX_VERSION = 1.0 export IMG_NGINX_VERSION = 1.0
# limpia todo # limpia todo


+ 1
- 0
ReyMotaAppsDj/requirements.txt View File

@ -11,3 +11,4 @@ pyflakes==3.2.0
sqlparse==0.5.1 sqlparse==0.5.1
typing_extensions==4.12.2 typing_extensions==4.12.2
django-calculation==1.0.0 django-calculation==1.0.0
pandas==2.2.3

+ 11
- 10
ReyMotaAppsDj/reymota/lyrics/management/commands/importa_song.py View File

@ -3,6 +3,7 @@ from lyrics.models import Album, Artista, Song
import csv import csv
import argparse import argparse
from datetime import datetime from datetime import datetime
import pandas as pd
class Command(BaseCommand): class Command(BaseCommand):
@ -13,13 +14,13 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
fichero = options["fichero_csv"] 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)
contenido = pd.read_csv(fichero)
for fila in contenido.iterrows():
print(fila[1].title, ", ", fila[1].artist, ", ", fila[1].album)
artista = Artista.objects.get(nombre=fila[1].artist)
album = Album.objects.get(pk=fila[1].album)
cancion = Song(title=fila[1].title, artist=artista, album=album, pista=fila[1].pista, lyrics=fila[1].lyrics)
cancion.save()

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

@ -74,7 +74,9 @@ def lista_albumes(request):
@login_required @login_required
def detalle_album(request, album_id): def detalle_album(request, album_id):
album = get_object_or_404(Album, pk=album_id) album = get_object_or_404(Album, pk=album_id)
return render(request, 'lyrics/detalle_album.html', {'album': album})
songs = Song.objects.filter(album_id=album_id)
return render(request, 'lyrics/detalle_album.html', {'album': album, 'songs': songs})
@login_required @login_required


+ 26
- 1
ReyMotaAppsDj/reymota/templates/lyrics/detalle_album.html View File

@ -23,7 +23,7 @@
<h4 class="notification-title mb-1">{{ album.name }}</h4> <h4 class="notification-title mb-1">{{ album.name }}</h4>
<ul class="notification-meta list-inline mb-0"> <ul class="notification-meta list-inline mb-0">
<li class="list-inline-item"><a href="{% url 'lyrics:detalle_album' album_id=album.id %}">{{ album.album.name }}</a></li> <li class="list-inline-item"><a href="{% url 'lyrics:detalle_album' album_id=album.id %}">{{ album.album.name }}</a></li>
<li class="list-inline-item">|</li> <li class="list-inline-item">|</li>
@ -36,5 +36,30 @@
</tr> </tr>
</div><!--//row--> </div><!--//row-->
</div><!--//app-card-header--> </div><!--//app-card-header-->
<div class="app-card-body p-4">
{% if songs %}
<table class="table app-table-hover mb-0 text-left">
<thead>
<tr>
<th>Pista</th>
<th>Título</th>
<th>Autor</th>
</tr>
</thead>
<tbody>
{% for song in songs %}
<tr>
<td class="cell">{{ song.pista }}</td>
<td class="cell"><a href="{% url 'lyrics:detalle_song' song_id=song.id %}">{{ song.title }}</a></td>
<td class="cell">{{ song.author }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No songs found matching your query.</p>
{% endif %}
</div>
</div><!--//app-card--> </div><!--//app-card-->
{% endblock %} {% endblock %}

Loading…
Cancel
Save