Browse Source

Preparado para añadir carátulas

politica
Celestino Rey 1 year ago
parent
commit
048914cae4
8 changed files with 45 additions and 6 deletions
  1. BIN
      LyricsPy/servicios/instance/songs.db
  2. +2
    -0
      LyricsPy/servicios/lyrics/__init__.py
  3. +2
    -1
      LyricsPy/servicios/lyrics/models.py
  4. +23
    -2
      LyricsPy/servicios/lyrics/paginas.py
  5. BIN
      LyricsPy/servicios/lyrics/static/uploads/theriver.jpg
  6. +4
    -1
      LyricsPy/servicios/lyrics/templates/add_album.html
  7. +5
    -1
      LyricsPy/servicios/lyrics/templates/album.html
  8. +9
    -1
      LyricsPy/servicios/lyrics/templates/index.html

BIN
LyricsPy/servicios/instance/songs.db View File


+ 2
- 0
LyricsPy/servicios/lyrics/__init__.py View File

@ -11,6 +11,8 @@ def create_app():
app.config['SECRET_KEY'] = 'secret-key-goes-here' app.config['SECRET_KEY'] = 'secret-key-goes-here'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///songs.db' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///songs.db'
app.config['UPLOAD_FOLDER'] = 'lyrics/static/uploads'
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB máximo
from .models import db from .models import db


+ 2
- 1
LyricsPy/servicios/lyrics/models.py View File

@ -7,6 +7,7 @@ class Album(db.Model):
name = db.Column(db.String(100), nullable=False) name = db.Column(db.String(100), nullable=False)
artist = db.Column(db.String(100), nullable=False) artist = db.Column(db.String(100), nullable=False)
year = db.Column(db.Integer, nullable=False) year = db.Column(db.Integer, nullable=False)
cover_image = db.Column(db.String(100), nullable=True)
songs = db.relationship('Song', backref='album', lazy=True) songs = db.relationship('Song', backref='album', lazy=True)
def __repr__(self): def __repr__(self):
@ -18,7 +19,7 @@ class Song(db.Model):
author = db.Column(db.String(100), nullable=False) author = db.Column(db.String(100), nullable=False)
album_id = db.Column(db.Integer, db.ForeignKey('album.id'), nullable=False) album_id = db.Column(db.Integer, db.ForeignKey('album.id'), nullable=False)
lyrics = db.Column(db.Text, nullable=False) lyrics = db.Column(db.Text, nullable=False)
pista = db.Column(db.Integer, nullable=False) # Nuevo campo
pista = db.Column(db.Integer, nullable=False)
def __repr__(self): def __repr__(self):


+ 23
- 2
LyricsPy/servicios/lyrics/paginas.py View File

@ -1,4 +1,7 @@
from flask import Blueprint, render_template, request, redirect, url_for
from flask import Blueprint, render_template, request, redirect, url_for, current_app
from werkzeug.utils import secure_filename
import os
from .models import db, Song, Album from .models import db, Song, Album
bp = Blueprint("paginas", __name__) bp = Blueprint("paginas", __name__)
@ -36,11 +39,29 @@ def add_song():
@bp.route('/add_album', methods=['GET', 'POST']) @bp.route('/add_album', methods=['GET', 'POST'])
def add_album(): def add_album():
if request.method == 'POST': if request.method == 'POST':
name = request.form['name'] name = request.form['name']
artist = request.form['artist'] artist = request.form['artist']
year = request.form['year'] year = request.form['year']
new_album = Album(name=name, artist=artist, year=year)
# Verificar que el campo 'cover_image' está en request.files
if 'coverimage' not in request.files:
return "No file part in the request", 400
cover_image = request.files['coverimage']
# Verificar que se ha seleccionado un archivo
if cover_image.filename == '':
return "No selected file", 400
if cover_image:
image_filename = secure_filename(cover_image.filename)
cover_image.save(os.path.join(current_app.config['UPLOAD_FOLDER'], image_filename))
else:
image_filename = None
new_album = Album(name=name, artist=artist, year=year, cover_image=image_filename)
db.session.add(new_album) db.session.add(new_album)
db.session.commit() db.session.commit()


BIN
LyricsPy/servicios/lyrics/static/uploads/theriver.jpg View File

Before After
Width: 320  |  Height: 320  |  Size: 34 KiB

+ 4
- 1
LyricsPy/servicios/lyrics/templates/add_album.html View File

@ -2,7 +2,7 @@
{% block content %} {% block content %}
<h2>Añadir nuevo Álbum</h2> <h2>Añadir nuevo Álbum</h2>
<form method="POST">
<form method="POST" enctype="multipart/form-data">
<label for="name">Nombre:</label> <label for="name">Nombre:</label>
<input type="text" id="name" name="name" required> <input type="text" id="name" name="name" required>
@ -11,6 +11,9 @@
<label for="year">Año:</label> <label for="year">Año:</label>
<input type="number" id="year" name="year" required> <input type="number" id="year" name="year" required>
<label for="cover_image">Cover Image:</label>
<input type="file" id="cover_image" name="coverimage">
<button type="submit">Añadir álbum</button> <button type="submit">Añadir álbum</button>
</form> </form>


+ 5
- 1
LyricsPy/servicios/lyrics/templates/album.html View File

@ -4,7 +4,11 @@
<h2>{{ album.name }}</h2> <h2>{{ album.name }}</h2>
<p><strong>Artista:</strong> {{ album.artist }}</p> <p><strong>Artista:</strong> {{ album.artist }}</p>
<p><strong>Año:</strong> {{ album.year }}</p> <p><strong>Año:</strong> {{ album.year }}</p>
{% if album.cover_image %}
<p><img src="{{ url_for('static', filename='uploads/' ~ album.cover_image) }}" alt="{{ album.name }}" style="width:200px;height:200px;"></p>
{% else %}
<p>No hay imágen disponible</p>
{% endif %}
<h3>Canciones en este álbum</h3> <h3>Canciones en este álbum</h3>
<!-- <!--
<ul> <ul>


+ 9
- 1
LyricsPy/servicios/lyrics/templates/index.html View File

@ -39,7 +39,8 @@
{% if albums %} {% if albums %}
<table id="albumTable" class="display"> <table id="albumTable" class="display">
<thead> <thead>
<tr>
<tr>
<th>Cover</th>
<th>Nombre</th> <th>Nombre</th>
<th>Artista</th> <th>Artista</th>
<th>Año</th> <th>Año</th>
@ -48,6 +49,13 @@
<tbody> <tbody>
{% for album in albums %} {% for album in albums %}
<tr> <tr>
<td>
{% if album.cover_image %}
<img src="{{ url_for('static', filename='uploads/' ~ album.cover_image) }}" alt="{{ album.name }}" style="width:50px;height:50px;">
{% else %}
Sin imágen
{% endif %}
</td>
<td><a href="{{ url_for('paginas.album', album_id=album.id) }}">{{ album.name }}</a></td> <td><a href="{{ url_for('paginas.album', album_id=album.id) }}">{{ album.name }}</a></td>
<td>{{ album.artist }}</td> <td>{{ album.artist }}</td>
<td>{{ album.year }}</td> <td>{{ album.year }}</td>


Loading…
Cancel
Save