From 7d777814abb47b7b86a2c706cf3fc6a0c6bf8bd8 Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Wed, 19 Jun 2024 18:09:01 +0200 Subject: [PATCH] Funciona a la primera (casi) --- LyricsPy/app.py | 45 +++++++++++++++++++++++++++++++ LyricsPy/instance/songs.db | Bin 0 -> 16384 bytes LyricsPy/models.py | 14 ++++++++++ LyricsPy/templates/add_song.html | 23 ++++++++++++++++ LyricsPy/templates/base.html | 19 +++++++++++++ LyricsPy/templates/index.html | 12 +++++++++ LyricsPy/templates/song.html | 9 +++++++ 7 files changed, 122 insertions(+) create mode 100644 LyricsPy/app.py create mode 100644 LyricsPy/instance/songs.db create mode 100644 LyricsPy/models.py create mode 100644 LyricsPy/templates/add_song.html create mode 100644 LyricsPy/templates/base.html create mode 100644 LyricsPy/templates/index.html create mode 100644 LyricsPy/templates/song.html diff --git a/LyricsPy/app.py b/LyricsPy/app.py new file mode 100644 index 0000000..b9dfefc --- /dev/null +++ b/LyricsPy/app.py @@ -0,0 +1,45 @@ +from flask import Flask, render_template, request, redirect, url_for +from models import db, Song + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///songs.db' +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db.init_app(app) + +@app.before_request +def before_request(): + if not hasattr(app, 'db_initialized'): + db.create_all() + app.db_initialized = True + +@app.route('/') +def index(): + songs = Song.query.all() + return render_template('index.html', songs=songs) + +@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']) +def add_song(): + if request.method == 'POST': + title = request.form['title'] + author = request.form['author'] + year = request.form['year'] + album = request.form['album'] + lyrics = request.form['lyrics'] + + new_song = Song(title=title, author=author, year=year, album=album, lyrics=lyrics) + db.session.add(new_song) + db.session.commit() + + return redirect(url_for('index')) + + return render_template('add_song.html') + +if __name__ == '__main__': + with app.app_context(): + db.create_all() + app.run(debug=True) diff --git a/LyricsPy/instance/songs.db b/LyricsPy/instance/songs.db new file mode 100644 index 0000000000000000000000000000000000000000..664751f87afdfdadd6a299cdc9f4c8c5492cf647 GIT binary patch literal 16384 zcmeHOO>ZPg5$&E?w7V^}mdlC*mt-Z>Gg3FZfVk71vDOBAcCgKdxuEQ-?5>=ys;te- za&P;FIKi32{tHh03U2%zF1#1nHtyN6G$SD}BCWBjvhpJ$UPMM#<;yw$#fgnZEuC+4 zR6ibkdoUaheyY@9FnEmL_wal3GsMm7<(s$gVxH;$|8Mc>@tuikoF1a)!v8>n(eotJ0Fr}MK*_4C6^^~9D>M^C>6)Q2DagV?{9 zE)UHOS)YtRMj#`Q5y%K+1Tq2{f&T{t{$z$948H&AqwoE>KXENyz8j;S>+ON>3!~0E zZ}Bo7jcMQi`$c8cnGJYwpcmVzaxGdME4*0ut19Ad-I~pKba-X_HdbhcN3AiXDOGf+ zbQ`4?u8(T#`tj(}^c|G5Y-A|W96wit~RLp#`cnp z$D>;;cI6{e*BE!<%?2Y+RjK`2g}zO)BcSm%nDOX>gM|o|Pi<^nt3?g7caosrR_V6H zWjs1^eJ~1*q59H#D1T)ELQu9vd!trfhX6fn>Fu!2%MvX~D*Qb!jw{34!=@{rn2a7-twe6JNq#lTS__1`2j5pnP z<IyEF+JH!p)Dq9^ha8$p~ZwG6ETa zj6g;pBajiu2>jO&$lw3@`#*pG=kI^)Xkl|=|NAw6|KGpEmG-n=M{FOzy%I9~@bTXU z_?Le&0vUn-T?D@V(W4IrKl$|0{4c*d!2UW34s7gm)4t|j_&2GOzkcq)b69LHFFp2f z=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' diff --git a/LyricsPy/templates/add_song.html b/LyricsPy/templates/add_song.html new file mode 100644 index 0000000..7e15059 --- /dev/null +++ b/LyricsPy/templates/add_song.html @@ -0,0 +1,23 @@ +{% extends 'base.html' %} + +{% block content %} +

Add New Song

+
+ + + + + + + + + + + + + + + + +
+{% endblock %} diff --git a/LyricsPy/templates/base.html b/LyricsPy/templates/base.html new file mode 100644 index 0000000..f641da7 --- /dev/null +++ b/LyricsPy/templates/base.html @@ -0,0 +1,19 @@ + + + + + My Song Lyrics + + + +
+

My Song Lyrics

+ +
+ {% block content %}{% endblock %} +
+ + diff --git a/LyricsPy/templates/index.html b/LyricsPy/templates/index.html new file mode 100644 index 0000000..c86dc76 --- /dev/null +++ b/LyricsPy/templates/index.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} +

Song List

+ +{% endblock %} diff --git a/LyricsPy/templates/song.html b/LyricsPy/templates/song.html new file mode 100644 index 0000000..429ddfa --- /dev/null +++ b/LyricsPy/templates/song.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} + +{% block content %} +

{{ song.title }}

+

Author: {{ song.author }}

+

Year: {{ song.year }}

+

Album: {{ song.album }}

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