|
|
@ -1,6 +1,7 @@ |
|
|
from flask import Blueprint, render_template, request, redirect, url_for, current_app, send_from_directory |
|
|
from flask import Blueprint, render_template, request, redirect, url_for, current_app, send_from_directory |
|
|
from werkzeug.utils import secure_filename |
|
|
from werkzeug.utils import secure_filename |
|
|
from flask_login import login_user, logout_user, login_required |
|
|
from flask_login import login_user, logout_user, login_required |
|
|
|
|
|
from sqlalchemy import desc |
|
|
|
|
|
|
|
|
import os |
|
|
import os |
|
|
|
|
|
|
|
|
@ -66,14 +67,20 @@ def add_song(): |
|
|
@bp.route('/add_song2album/<int:album_id>', methods=['GET', 'POST']) |
|
|
@bp.route('/add_song2album/<int:album_id>', methods=['GET', 'POST']) |
|
|
@login_required |
|
|
@login_required |
|
|
def add_song2album(album_id): |
|
|
def add_song2album(album_id): |
|
|
|
|
|
album = Album.query.filter_by(id=album_id).first() # obtiene el album cuyo id hemos recibido |
|
|
|
|
|
|
|
|
|
|
|
ultimapista = Song.query.filter_by(album_id=album.id).order_by(desc(Song.pista)).first() |
|
|
|
|
|
|
|
|
|
|
|
if ultimapista: |
|
|
|
|
|
pista = ultimapista.pista + 1 |
|
|
|
|
|
print("Mayor: ", ultimapista.pista) |
|
|
|
|
|
else: |
|
|
|
|
|
pista = 1 |
|
|
|
|
|
print("No hay ninguna pista") |
|
|
|
|
|
|
|
|
if request.method == 'POST': |
|
|
if request.method == 'POST': |
|
|
title = request.form['title'] |
|
|
title = request.form['title'] |
|
|
# author = request.form['author'] |
|
|
|
|
|
# album_id = request.form['album_id'] |
|
|
|
|
|
lyrics = request.form['lyrics'] |
|
|
lyrics = request.form['lyrics'] |
|
|
pista = request.form['pista'] |
|
|
|
|
|
|
|
|
|
|
|
album = Album.query.filter_by(id=album_id).first() # obtiene el album cuyo id hemos recibido |
|
|
|
|
|
author = album.artist |
|
|
author = album.artist |
|
|
|
|
|
|
|
|
new_song = Song(title=title, author=author, album_id=album_id, lyrics=lyrics, pista=pista) |
|
|
new_song = Song(title=title, author=author, album_id=album_id, lyrics=lyrics, pista=pista) |
|
|
@ -83,7 +90,7 @@ def add_song2album(album_id): |
|
|
return redirect(url_for('paginas.album', album_id=album_id)) |
|
|
return redirect(url_for('paginas.album', album_id=album_id)) |
|
|
|
|
|
|
|
|
albums = Album.query.all() |
|
|
albums = Album.query.all() |
|
|
return render_template('add_song2album.html', album_id=album_id) |
|
|
|
|
|
|
|
|
return render_template('add_song2album.html', pista=pista, album=album, album_id=album_id) |
|
|
|
|
|
|
|
|
@bp.route('/add_album', methods=['GET', 'POST']) |
|
|
@bp.route('/add_album', methods=['GET', 'POST']) |
|
|
@login_required |
|
|
@login_required |
|
|
|