Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Editorial page #38

Merged
merged 5 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)\
Expand Down Expand Up @@ -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)\
Expand All @@ -183,6 +183,23 @@ def show_author(author_id):
)


@main.route('/show_editorial/<int:editorial_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, 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)\
.join(Genre)

return render_template('show_editorial.html',
greeting = current_user.name,
editorial = current_editorial,
books = editorial_books,
)


@main.route('/show_book/<int:book_id>')
@login_required
def show_book(book_id):
Expand All @@ -202,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)\
Expand Down
2 changes: 1 addition & 1 deletion app/templates/my_books.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1 class="title">Mis Libros</h1>
<th><a href="{{ url_for('main.show_author', author_id = book.id_author) }}">{{ book.author_name }}</a></th>
<th>{{ book.rating * '<i class="bi bi-star-fill"></i>' |safe }}</th>
<th><a href="{{ url_for('main.show_genre', genre_id = book.id_genre) }}">{{ book.genre_name }}</a></th>
<th>{{ book.editorial_name }}</th>
<th><a href="{{ url_for('main.show_editorial', editorial_id = book.id_editorial ) }}">{{ book.editorial_name }}</a></th>
</tr>
{% endfor %}
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions app/templates/show_author.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ <h3>{{a.country}}</h3>
<tr>
<th><a href="{{ url_for('main.show_book', book_id = book.id) }}">{{ book.title }}</a></th>
<th>{{ book.rating * '<i class="bi bi-star-fill"></i>' |safe }}</th>
<th>{{ book.genre_name }}</th>
<th>{{ book.editorial_name }}</th>
<th><a href="{{ url_for('main.show_genre', genre_id = book.id_genre) }}">{{ book.genre_name }}</a></th>
<th><a href="{{ url_for('main.show_editorial', editorial_id = book.id_editorial) }}">{{ book.editorial_name }}</a></th>
</tr>
{% endfor %}
</table>
Expand Down
28 changes: 28 additions & 0 deletions app/templates/show_editorial.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'base.html' %}

{% block content %}
<div class="hero-body">
<div class="container has-text-justified is-fluid">
{% for e in editorial %}
<h1 class="Title">{{e.name}}</h1>
{% endfor %}
<br>
<table class="table is-fullwidth">
<tr class="has-background-success-light">
<th>Título</th>
<th>Puntuación</th>
<th>Género</th>
<th>Autor</th>
</tr>
{% for book in books %}
<tr>
<th><a href="{{ url_for('main.show_book', book_id = book.id) }}">{{ book.title }}</a></th>
<th>{{ book.rating * '<i class="bi bi-star-fill"></i>' |safe }}</th>
<th><a href="{{ url_for('main.show_author', author_id = book.id_author) }}">{{ book.author_name }}</a></th>
<th><a href="{{ url_for('main.show_genre', genre_id = book.id_genre) }}">{{ book.genre_name }}</a></th>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion app/templates/show_genre.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1 class="Title">{{ g.name }}</h1>
<th><a href="{{ url_for('main.show_book', book_id = book.id) }}">{{ book.title }}</a></th>
<th><a href="{{ url_for('main.show_author', author_id = book.id_author) }}">{{book.author_name}}</a></th>
<th>{{ book.rating * '<i class="bi bi-star-fill"></i>' |safe }}</th>
<th>{{ book.editorial_name }}</th>
<th><a href="{{ url_for('main.show_editorial', editorial_id = book.id_editorial) }}">{{ book.editorial_name }}</a></th>
</tr>
{% endfor %}
</table>
Expand Down