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 664751f..7c59f1f 100644 Binary files a/LyricsPy/instance/songs.db and b/LyricsPy/instance/songs.db differ diff --git a/LyricsPy/models.py b/LyricsPy/models.py index 2ea8fdc..edc40ae 100644 --- a/LyricsPy/models.py +++ b/LyricsPy/models.py @@ -2,12 +2,21 @@ from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() +class Album(db.Model): + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(100), nullable=False) + artist = db.Column(db.String(100), nullable=False) + year = db.Column(db.Integer, nullable=False) + songs = db.relationship('Song', backref='album', lazy=True) + + def __repr__(self): + return f'' + 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 %}