From c63f603ef99f1e5a19a32e9414a431463d956377 Mon Sep 17 00:00:00 2001 From: Boris Quiroz Date: Wed, 14 Jun 2023 20:38:26 -0400 Subject: [PATCH 1/5] Add route to show editorial and id_editorial for ref --- app/main.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index a86196a..aa60874 100644 --- a/app/main.py +++ b/app/main.py @@ -135,7 +135,7 @@ def edit_book(book_id): @main.route('/my_books') @login_required def books(): - filtered_books = db.session.query(Book.id, Book.title, Book.rating, Book.id_author, Book.id_genre, Author.name.label('author_name'), Editorial.name.label('editorial_name'), Genre.name.label('genre_name'))\ + filtered_books = db.session.query(Book.id, Book.title, Book.rating, Book.id_author, Book.id_genre, Book.id_editorial, Author.name.label('author_name'), Editorial.name.label('editorial_name'), Genre.name.label('genre_name'))\ .join(Author)\ .join(Editorial)\ .join(Genre)\ @@ -183,6 +183,23 @@ def show_author(author_id): ) +@main.route('/show_editorial/') +@login_required +def show_editorial(editorial_id): + current_editorial = db.session.query(Editorial.name).filter(Editorial.id == editorial_id) + editorial_books = db.session.query(Book.id, Book.title, Book.year, Book.pages, Book.rating, Author.name.label('author_name'), Genre.name.label('genre_name'))\ + .filter(Book.id_editorial == editorial_id)\ + .join(Author)\ + .join(Editorial)\ + .join(Genre) + + return render_template('show_editorial.html', + greeting = current_user.name, + editorial = current_editorial, + books = editorial_books, + ) + + @main.route('/show_book/') @login_required def show_book(book_id): From e6e6651d9da04863241e7a6b2c816a4d8806b05c Mon Sep 17 00:00:00 2001 From: Boris Quiroz Date: Wed, 14 Jun 2023 20:38:57 -0400 Subject: [PATCH 2/5] Link to editorial --- app/templates/my_books.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/my_books.html b/app/templates/my_books.html index cec832b..2a3c35a 100644 --- a/app/templates/my_books.html +++ b/app/templates/my_books.html @@ -22,7 +22,7 @@

Mis Libros

{{ book.author_name }} {{ book.rating * '' |safe }} {{ book.genre_name }} - {{ book.editorial_name }} + {{ book.editorial_name }} {% endfor %} From 973d1ea1bd05bdfb38d91b8c8bab1edfa1cee261 Mon Sep 17 00:00:00 2001 From: Boris Quiroz Date: Wed, 14 Jun 2023 20:39:08 -0400 Subject: [PATCH 3/5] Show editorial template --- app/templates/show_editorial.html | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/templates/show_editorial.html diff --git a/app/templates/show_editorial.html b/app/templates/show_editorial.html new file mode 100644 index 0000000..1394aa9 --- /dev/null +++ b/app/templates/show_editorial.html @@ -0,0 +1,28 @@ +{% extends 'base.html' %} + +{% block content %} +
+
+ {% for e in editorial %} +

{{e.name}}

+ {% endfor %} +
+ + + + + + + + {% for book in books %} + + + + + + + {% endfor %} +
TítuloPuntuaciónGéneroAutor
{{ book.title }}{{ book.rating * '' |safe }}{{ book.genre_name }}{{ book.author_name }}
+
+
+{% endblock %} From fa6d20c709381f6953fd2bb1b3ac9706a4e9016e Mon Sep 17 00:00:00 2001 From: Boris Quiroz Date: Wed, 14 Jun 2023 21:48:03 -0400 Subject: [PATCH 4/5] Add needed attributes to be used in the views --- app/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index aa60874..9ded1c2 100644 --- a/app/main.py +++ b/app/main.py @@ -170,7 +170,7 @@ def profile(): @login_required def show_author(author_id): current_author = db.session.query(Author.name, Author.country).filter(Author.id == author_id) - author_books = db.session.query(Book.id, Book.title, Book.year, Book.pages, Book.rating, Editorial.name.label('editorial_name'), Genre.name.label('genre_name'))\ + author_books = db.session.query(Book.id, Book.title, Book.year, Book.pages, Book.rating, Book.id_editorial, Book.id_genre, Editorial.name.label('editorial_name'), Genre.name.label('genre_name'))\ .filter(Book.id_author == author_id)\ .join(Author)\ .join(Editorial)\ @@ -187,7 +187,7 @@ def show_author(author_id): @login_required def show_editorial(editorial_id): current_editorial = db.session.query(Editorial.name).filter(Editorial.id == editorial_id) - editorial_books = db.session.query(Book.id, Book.title, Book.year, Book.pages, Book.rating, Author.name.label('author_name'), Genre.name.label('genre_name'))\ + editorial_books = db.session.query(Book.id, Book.title, Book.year, Book.pages, Book.rating, Book.id_author, Book.id_genre, Author.name.label('author_name'), Genre.name.label('genre_name'))\ .filter(Book.id_editorial == editorial_id)\ .join(Author)\ .join(Editorial)\ @@ -219,7 +219,7 @@ def show_book(book_id): @login_required def show_genre(genre_id): current_genre = db.session.query(Genre.name).filter(Genre.id == genre_id) - genre_books = db.session.query(Book.id, Book.title, Book.id_author, Book.rating, Editorial.name.label('editorial_name'), Author.name.label('author_name'))\ + genre_books = db.session.query(Book.id, Book.title, Book.id_author, Book.rating, Book.id_editorial, Editorial.name.label('editorial_name'), Author.name.label('author_name'))\ .filter(Book.id_genre == genre_id)\ .join(Author)\ .join(Editorial)\ From 9356fbe076000e761fd973bf091930a9abe62647 Mon Sep 17 00:00:00 2001 From: Boris Quiroz Date: Wed, 14 Jun 2023 21:48:42 -0400 Subject: [PATCH 5/5] Link everything --- app/templates/show_author.html | 4 ++-- app/templates/show_editorial.html | 4 ++-- app/templates/show_genre.html | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/templates/show_author.html b/app/templates/show_author.html index dbb3fde..6f13a71 100644 --- a/app/templates/show_author.html +++ b/app/templates/show_author.html @@ -19,8 +19,8 @@

{{a.country}}

{{ book.title }} {{ book.rating * '' |safe }} - {{ book.genre_name }} - {{ book.editorial_name }} + {{ book.genre_name }} + {{ book.editorial_name }} {% endfor %} diff --git a/app/templates/show_editorial.html b/app/templates/show_editorial.html index 1394aa9..05e6b6c 100644 --- a/app/templates/show_editorial.html +++ b/app/templates/show_editorial.html @@ -18,8 +18,8 @@

{{e.name}}

{{ book.title }} {{ book.rating * '' |safe }} - {{ book.genre_name }} - {{ book.author_name }} + {{ book.author_name }} + {{ book.genre_name }} {% endfor %} diff --git a/app/templates/show_genre.html b/app/templates/show_genre.html index a67a2f5..6829b7d 100644 --- a/app/templates/show_genre.html +++ b/app/templates/show_genre.html @@ -19,7 +19,7 @@

{{ g.name }}

{{ book.title }} {{book.author_name}} {{ book.rating * '' |safe }} - {{ book.editorial_name }} + {{ book.editorial_name }} {% endfor %}