From 188ea44f620c088e27dc73539064c86e2dbde3dd Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Fri, 19 Jul 2024 12:04:16 +0200 Subject: [PATCH] =?UTF-8?q?Cambios=20para=20editar=20album=20y=20canci?= =?UTF-8?q?=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LyricsPy/K8S/Makefile | 2 +- LyricsPy/servicios/Dockerfile | 1 + LyricsPy/servicios/env.produccion | 1 + LyricsPy/servicios/lanza.sh | 6 ++- LyricsPy/servicios/lyrics/__init__.py | 2 +- LyricsPy/servicios/lyrics/paginas.py | 40 ++++++++++++++++ .../lyrics/templates/albumescard.html | 10 ++-- .../lyrics/templates/edit_album.html | 39 ++++++++++++++++ .../servicios/lyrics/templates/edit_song.html | 46 +++++++++++++++++++ LyricsPy/servicios/lyrics/templates/song.html | 4 ++ LyricsPy/servicios/requirements.txt | 1 + 11 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 LyricsPy/servicios/env.produccion create mode 100644 LyricsPy/servicios/lyrics/templates/edit_album.html create mode 100644 LyricsPy/servicios/lyrics/templates/edit_song.html diff --git a/LyricsPy/K8S/Makefile b/LyricsPy/K8S/Makefile index 28230ff..4a08a31 100644 --- a/LyricsPy/K8S/Makefile +++ b/LyricsPy/K8S/Makefile @@ -1,4 +1,4 @@ -export IMG_VERSION = 7.1 +export IMG_VERSION = 7.2 imagen: cd ../servicios; make diff --git a/LyricsPy/servicios/Dockerfile b/LyricsPy/servicios/Dockerfile index 67ca6b1..f180a8e 100644 --- a/LyricsPy/servicios/Dockerfile +++ b/LyricsPy/servicios/Dockerfile @@ -15,6 +15,7 @@ COPY requirements.txt requirements.txt RUN pip3 install -r requirements.txt COPY . . +COPY env.produccion .env # run entrypoint.sh ENTRYPOINT ["/lyrics/entrypoint.sh"] \ No newline at end of file diff --git a/LyricsPy/servicios/env.produccion b/LyricsPy/servicios/env.produccion new file mode 100644 index 0000000..f1fd512 --- /dev/null +++ b/LyricsPy/servicios/env.produccion @@ -0,0 +1 @@ +ENVIRONMENT="Producción" \ No newline at end of file diff --git a/LyricsPy/servicios/lanza.sh b/LyricsPy/servicios/lanza.sh index 6d1d06b..cd15a2a 100644 --- a/LyricsPy/servicios/lanza.sh +++ b/LyricsPy/servicios/lanza.sh @@ -1 +1,5 @@ -python -m flask --app lyrics run \ No newline at end of file +#python -m flask --app lyrics run + +export FLASK_DEBUG=1 +export FLASK_APP=lyrics +flask run \ No newline at end of file diff --git a/LyricsPy/servicios/lyrics/__init__.py b/LyricsPy/servicios/lyrics/__init__.py index f0a53bd..7f58838 100644 --- a/LyricsPy/servicios/lyrics/__init__.py +++ b/LyricsPy/servicios/lyrics/__init__.py @@ -46,7 +46,7 @@ def create_app(): print(f"Current Environment: {os.getenv('ENVIRONMENT')}") - print(f"Using Database: {app.config.get('DATABASE')}") + print(f"Using Database: {app.config.get('SQLALCHEMY_DATABASE_URI')}") print(f"Directorio de uploads: {app.config.get('UPLOAD_FOLDER')}") print(f"instance: {app.instance_path}") diff --git a/LyricsPy/servicios/lyrics/paginas.py b/LyricsPy/servicios/lyrics/paginas.py index fedc23d..ea36762 100644 --- a/LyricsPy/servicios/lyrics/paginas.py +++ b/LyricsPy/servicios/lyrics/paginas.py @@ -65,6 +65,25 @@ def add_song(): albums = Album.query.all() return render_template('add_song.html', albums=albums) +@bp.route('/edit_song/', methods=['GET', 'POST']) +@login_required +def edit_song(song_id): + song = Song.query.get_or_404(song_id) + albums = Album.query.all() + if request.method == 'POST': + song.title = request.form['title'] + song.author = request.form['author'] + song.order = request.form['order'] + song.album_id = request.form['album_id'] + song.lyrics = request.form['lyrics'] + + db.session.commit() + return redirect(url_for('song', song_id=song.id)) + + albums = Album.query.all() + + return render_template('edit_song.html', song=song, albums=albums) + @bp.route('/add_song2album/', methods=['GET', 'POST']) @login_required def add_song2album(album_id): @@ -127,6 +146,27 @@ def add_album(): return render_template('add_album.html') +@bp.route('/edit_album/', methods=['GET', 'POST']) +@login_required +def edit_album(album_id): + album = Album.query.get_or_404(album_id) + if request.method == 'POST': + album.name = request.form['name'] + album.artist = request.form['artist'] + album.year = request.form['year'] + + if 'cover_image' in request.files: + cover_image = request.files['cover_image'] + if cover_image.filename != '': + image_filename = secure_filename(cover_image.filename) + cover_image.save(os.path.join(bp.config['UPLOAD_FOLDER'], image_filename)) + album.cover_image = image_filename + + db.session.commit() + return redirect(url_for('album', album_id=album.id)) + + return render_template('edit_album.html', album=album) + @bp.route('/album/') def album(album_id): album = Album.query.get_or_404(album_id) diff --git a/LyricsPy/servicios/lyrics/templates/albumescard.html b/LyricsPy/servicios/lyrics/templates/albumescard.html index 19e0ba1..ccca840 100644 --- a/LyricsPy/servicios/lyrics/templates/albumescard.html +++ b/LyricsPy/servicios/lyrics/templates/albumescard.html @@ -55,13 +55,14 @@ diff --git a/LyricsPy/servicios/lyrics/templates/edit_album.html b/LyricsPy/servicios/lyrics/templates/edit_album.html new file mode 100644 index 0000000..7b0c982 --- /dev/null +++ b/LyricsPy/servicios/lyrics/templates/edit_album.html @@ -0,0 +1,39 @@ +{% extends 'base.html' %} + +{% block content %} +
+ +

Editar Álbum

+
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + {% if album.cover_image %} + {{ album.name }}
+ {% endif %} +
+ +
+ +
+
+
+
+{% endblock %} diff --git a/LyricsPy/servicios/lyrics/templates/edit_song.html b/LyricsPy/servicios/lyrics/templates/edit_song.html new file mode 100644 index 0000000..89e78fe --- /dev/null +++ b/LyricsPy/servicios/lyrics/templates/edit_song.html @@ -0,0 +1,46 @@ +{% extends 'base.html' %} + +{% block content %} +
+

Añadir nueva canción

+
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+
+{% endblock %} diff --git a/LyricsPy/servicios/lyrics/templates/song.html b/LyricsPy/servicios/lyrics/templates/song.html index c7d2454..ec319d2 100644 --- a/LyricsPy/servicios/lyrics/templates/song.html +++ b/LyricsPy/servicios/lyrics/templates/song.html @@ -24,6 +24,10 @@ +
+

Editar

+
+
diff --git a/LyricsPy/servicios/requirements.txt b/LyricsPy/servicios/requirements.txt index 99749ea..c453992 100644 --- a/LyricsPy/servicios/requirements.txt +++ b/LyricsPy/servicios/requirements.txt @@ -9,6 +9,7 @@ itsdangerous==2.2.0 Jinja2==3.1.4 MarkupSafe==2.1.5 packaging==24.1 +python-dotenv==1.0.1 SQLAlchemy==2.0.31 typing_extensions==4.12.2 Werkzeug==3.0.3