From 7d306528b232e088340e08ab853677e7e69c4639 Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Wed, 19 Jun 2024 20:20:14 +0200 Subject: [PATCH] =?UTF-8?q?Tabla=20de=20canciones=20y=20=C3=A1lbumes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LyricsPy/app.py | 30 ++++++++--- LyricsPy/instance/songs.db | Bin 16384 -> 20480 bytes LyricsPy/models.py | 13 ++++- LyricsPy/static/style.css | 85 ++++++++++++++++++++++++++++++ LyricsPy/templates/add_album.html | 17 ++++++ LyricsPy/templates/add_song.html | 19 +++---- LyricsPy/templates/base.html | 9 ++-- LyricsPy/templates/index.html | 11 +++- LyricsPy/templates/song.html | 4 +- 9 files changed, 163 insertions(+), 25 deletions(-) create mode 100644 LyricsPy/static/style.css create mode 100644 LyricsPy/templates/add_album.html diff --git a/LyricsPy/app.py b/LyricsPy/app.py index b9dfefc..53f3c38 100644 --- a/LyricsPy/app.py +++ b/LyricsPy/app.py @@ -1,5 +1,5 @@ from flask import Flask, render_template, request, redirect, url_for -from models import db, Song +from models import db, Song, Album app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///songs.db' @@ -15,29 +15,45 @@ def before_request(): @app.route('/') def index(): songs = Song.query.all() - return render_template('index.html', songs=songs) + albums = Album.query.all() + return render_template('index.html', songs=songs, albums=albums) @app.route('/song/') def song(song_id): song = Song.query.get_or_404(song_id) return render_template('song.html', song=song) -@app.route('/add', methods=['GET', 'POST']) +@app.route('/add_song', methods=['GET', 'POST']) def add_song(): if request.method == 'POST': title = request.form['title'] author = request.form['author'] - year = request.form['year'] - album = request.form['album'] + album_id = request.form['album_id'] lyrics = request.form['lyrics'] - new_song = Song(title=title, author=author, year=year, album=album, lyrics=lyrics) + new_song = Song(title=title, author=author, album_id=album_id, lyrics=lyrics) db.session.add(new_song) db.session.commit() return redirect(url_for('index')) - return render_template('add_song.html') + albums = Album.query.all() + return render_template('add_song.html', albums=albums) + +@app.route('/add_album', methods=['GET', 'POST']) +def add_album(): + if request.method == 'POST': + name = request.form['name'] + artist = request.form['artist'] + year = request.form['year'] + + new_album = Album(name=name, artist=artist, year=year) + db.session.add(new_album) + db.session.commit() + + return redirect(url_for('index')) + + return render_template('add_album.html') if __name__ == '__main__': with app.app_context(): diff --git a/LyricsPy/instance/songs.db b/LyricsPy/instance/songs.db index 664751f87afdfdadd6a299cdc9f4c8c5492cf647..7c59f1f647057b1989cfa0d7c080fa8ed265f537 100644 GIT binary patch delta 2725 zcmaJ@&u<$=6t*2wt1hl7q6$AQPpVK_$!!j$LgfHTf>Q!%Qn`kxr)s=A_72|Nab{+{ z>}gXtaij8u6Dl0Jpa>x@NSrwEFL2<5MCpNlpclS3>y)4ZQEb_>^L~Brd*AcnVg2wy z{j*ojovPJp%Xl6CHSTw>;_%As(>9J8XZLHJTW9x=4t{UHcyHEduADz#|76dJVJxjq z$NXBFU+qku6Y(%h?y8WscL%*2z5e{?&b6{jt3DOVsae_4>Wt z&E9SDhjdYems*$ZU9LA*R#xgCU-u#WBmdUe?Dy6OJsPZU?DURJTBrYxN4t9i+I@d# zhhwH9k@Ug({KwA9DPf$lZvI2(<@pz#m*#(Vo`2R?)_G9t{M31Hbnx}r`-hLx3ytO4 zg|)_pHYp7>^|N%tWPzmHQ=?F)lQM07f4#n3+goegFj6``r7fcqTF>k-GX>oeX40kI zEAL);+VnfdxZZipFfVr=A07O%)cX8{I%w0t+{!0aJ^aHf1}Z?y}DNa>h(dCrJ*#`*CKo>oyH)N zWCN6uQmC~d8;itt>83Ens-@6KYsu!Kue zAReVAECfhhULNT6*=VP!l5Q4rzy+OZ3hr8E@5 zgj8x(C~+)IjI_Ew*d*0?p+pXK0@2ujh4TOd9Qz`HSUJM0# zCJmYlYwNPGs7|LI@S6gh@ZARuMmz)FBrd%TS71;V*n!83{Eau<7nr2#vdxkN{G1w5 zFePwp=C5pl8-lEuDbB)aGRguP4gz5C(K;SKFmqq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y3f8eyd)BLparC15%>&ebaFFAE%AvN}AxfEv-hU9U~B=3baD3u=z|*MuQP3ZC5+| zmm=iqL>!cT(}mQEDm7Bn+|vhrP&%BiDoh(yC(p@NVBZ)buszKJHmAp?3R!*LQ2J*J+NcB`;K~9bL+u6#^z_7ICZa{g@A~~e`wyU|# z4T>g!A-d)b4c=6{0(C90gKk}i(Vl?{sS=CCiq&q=@#vhJ>u5HsKwE$eS%UfX?54JhSp;1d_~lY`p&}&s(^W!Lm^?qmVm5c*G7k8H+;0vM?lk{ zj$jlP3NT!douJzQM;76_3J7w@G$L6r?D@msbBuM{9=rYE*{CE`f<;>>4&=noLWha& z#E4wd2KGUF5qujRw<1Jo@J_Bw13C}3Yu1>V=!cF%GnKk5x6qmjLra{0lh#3BfvNz? zi@sRPli2%K^<8=>LU!1o5s_ZJVG4{#Ux0-uz{Wuh&|I}$!%?aV0 z-E!)Hl6m83=X5*3DczARP;;D$|yzAZnrHkx@Z!!&H6p+|VEB$jZ_dQFj%J zQ}~BWB#pBXaRyVjY9TcwFNr(Gm2O*QzUoXN%{eRLCwF2GjOwhR(M6@J?l37E2$iuDl#OSkayo51JEGJIc7=^lBX&SZOb&ljM0I*_S{h zVAd3TrBK?mNgr*2Jxr zwQ7o`CnW=y3y83;u~zgtR$Gu3y1K7c@rcfsDnGK_nVeJnxhSuD>(VL zy1ll58{)7gIK0YmV3g@9_>^TdLoNJE5LJbj6+XrC*taOhzJ=;=)U9l#uQZ2{iLpB- zA!%6>JdQ-*m3C)urW zlmrVs{K5s<7P=Dyz|kYTY)gG*rUA%;VGj2rX$%KWXw|X!VrLICg!I5MqjdAG4fbBiztQ' + class Song(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) author = db.Column(db.String(100), nullable=False) - year = db.Column(db.Integer, nullable=False) - album = db.Column(db.String(100), nullable=False) + album_id = db.Column(db.Integer, db.ForeignKey('album.id'), nullable=False) lyrics = db.Column(db.Text, nullable=False) def __repr__(self): diff --git a/LyricsPy/static/style.css b/LyricsPy/static/style.css new file mode 100644 index 0000000..8fd5894 --- /dev/null +++ b/LyricsPy/static/style.css @@ -0,0 +1,85 @@ +body { + font-family: Arial, sans-serif; + background-color: #f8f9fa; + color: #343a40; + margin: 0; + padding: 0; +} + +.container { + max-width: 800px; + margin: 50px auto; + padding: 20px; + background-color: #ffffff; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + border-radius: 8px; +} + +h1, h2 { + color: #007bff; +} + +nav { + margin-bottom: 20px; +} + +nav a { + margin-right: 15px; + text-decoration: none; + color: #007bff; +} + +nav a:hover { + text-decoration: underline; +} + +ul { + list-style-type: none; + padding: 0; +} + +li { + margin-bottom: 10px; +} + +form { + display: flex; + flex-direction: column; +} + +label { + margin-top: 10px; + margin-bottom: 5px; +} + +input[type="text"], +input[type="number"], +textarea, +select { + padding: 10px; + border: 1px solid #ced4da; + border-radius: 4px; + font-size: 16px; +} + +button { + margin-top: 20px; + padding: 10px 15px; + background-color: #007bff; + border: none; + color: white; + border-radius: 4px; + font-size: 16px; + cursor: pointer; +} + +button:hover { + background-color: #0056b3; +} + +pre { + background-color: #f8f9fa; + padding: 10px; + border: 1px solid #ced4da; + border-radius: 4px; +} diff --git a/LyricsPy/templates/add_album.html b/LyricsPy/templates/add_album.html new file mode 100644 index 0000000..4b036ae --- /dev/null +++ b/LyricsPy/templates/add_album.html @@ -0,0 +1,17 @@ +{% extends 'base.html' %} + +{% block content %} +

Añadir nuevo Álbum

+
+ + + + + + + + + + +
+{% endblock %} diff --git a/LyricsPy/templates/add_song.html b/LyricsPy/templates/add_song.html index 7e15059..5c31066 100644 --- a/LyricsPy/templates/add_song.html +++ b/LyricsPy/templates/add_song.html @@ -1,23 +1,24 @@ {% extends 'base.html' %} {% block content %} -

Add New Song

+

Añadir nueva canción

- + - + - - - - - + + - +
{% endblock %} diff --git a/LyricsPy/templates/base.html b/LyricsPy/templates/base.html index f641da7..f8e7f95 100644 --- a/LyricsPy/templates/base.html +++ b/LyricsPy/templates/base.html @@ -2,15 +2,16 @@ - My Song Lyrics + Mis Letras de Canciones
-

My Song Lyrics

+

Mis Letras de Canciones


{% block content %}{% endblock %} diff --git a/LyricsPy/templates/index.html b/LyricsPy/templates/index.html index c86dc76..ec5a843 100644 --- a/LyricsPy/templates/index.html +++ b/LyricsPy/templates/index.html @@ -1,7 +1,7 @@ {% extends 'base.html' %} {% block content %} -

Song List

+

Lista de canciones

    {% for song in songs %}
  • @@ -9,4 +9,13 @@
  • {% endfor %}
+
+

Álbumes

+
    + {% for album in albums %} +
  • {{ album.name }} by {{ album.artist }} ({{ album.year }})
  • + {% endfor %} +
+
+Añadir nuevo álbum {% endblock %} diff --git a/LyricsPy/templates/song.html b/LyricsPy/templates/song.html index 429ddfa..7be17a7 100644 --- a/LyricsPy/templates/song.html +++ b/LyricsPy/templates/song.html @@ -3,7 +3,7 @@ {% block content %}

{{ song.title }}

Author: {{ song.author }}

-

Year: {{ song.year }}

-

Album: {{ song.album }}

+

Year: {{ song.album.year }}

+

Album: {{ song.album.name }}

{{ song.lyrics }}
{% endblock %}