Skip to content

Commit

Permalink
Merge branch 'development' into 'master'
Browse files Browse the repository at this point in the history
resolves bug/flask-category_selection-no_quotes-books_templates

See merge request memphis-tools/dummy_fastapi_flask_blog_app!508
  • Loading branch information
memphis-tools committed Feb 9, 2025
2 parents 458074b + 3c6ba7b commit 7a5a200
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
7 changes: 3 additions & 4 deletions app/packages/flask_app/project/book_routes_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,14 @@ def add_book():
Description: the add book Flask route.
"""
session = session_commands.get_a_database_session()
books_categories_query = session.query(BookCategory).all()
books_categories = [(i.id, i.title) for i in books_categories_query]
books_categories = get_books_categories(session)
form = forms.BookForm(books_categories=books_categories)
if form.validate_on_submit():
title = form.title.data
summary = form.summary.data
content = form.content.data
author = form.author.data
category_id_from_form = int(form.categories.data[0])
category_id_from_form = int(form.categories.data)
try:
category_id = (
session.query(BookCategory)
Expand All @@ -162,7 +161,7 @@ def add_book():
.id
)
except Exception:
flash("Saisie invalide, categorie livre non prevue.", "error")
flash(f"Saisie invalide, categorie livre non prevue {category_id}.", "error")
return render_template(
"add_book.html",
form=form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def return_random_quote():
quotes = session.query(Quote).all()
session.close()
total_quotes_indexes = len(quotes) - 1
random_quote = quotes[random.randint(0, total_quotes_indexes)]
random_quote = quotes[random.randint(0, total_quotes_indexes)] if len(quotes) > 0 else ""
return random_quote


Expand Down
2 changes: 2 additions & 0 deletions app/packages/flask_app/project/templates/books.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% block content %}
<div class="container">
<div class="section_intro">
{% if random_quote != "" %}
<i>
<p>
"{{ random_quote.quote }}"
Expand All @@ -13,6 +14,7 @@
{{ random_quote.author }} - {{ random_quote.book_title }}
</p>
</i>
{% endif %}
</div>
<h1>DUMMY BLOG - LES LIVRES</h1>
<div class="home-books-container">
Expand Down
17 changes: 15 additions & 2 deletions app/packages/flask_app/project/templates/user_any_books.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@ <h1>DUMMY BLOG - LIVRES DE {{ user_name|upper }}<h1>
<img src='{{ url_for("static", filename="img/" + book.book_picture_name) }}' align="middle" />
<legend>Auteur: {{ book.author }}</legend>
<div class="counters">
<legend>Commentaires: {{ book.nb_comments }}</legend>
<legend>Favoris: {{ book.nb_starred }}</legend>
<legend>Commentaires: {{ book.book_comments | length }}</legend>
<legend>Favoris: {{ book.starred | length }}</legend>
</div>
</div>
<hr />
{% endfor %}
</div>
{% if total_books > per_page %}
<div class="pagination_block d-flex flex-row justify-content-center gap-3">
<a href="{{ url_for('user_routes_blueprint.user_books', user_id=user_id, page=1) }}">Premiers</a>
{% if page > 1 %}
<a href="{{ url_for('user_routes_blueprint.user_books', user_id=user_id, page=page-1) }}">Précédents</a>
{% endif %}
Page {{ page }} sur {{ total_pages }}
{% if page < total_pages %}
<a href="{{ url_for('user_routes_blueprint.user_books', user_id=user_id, page=page+1) }}">Prochains</a>
{% endif %}
<a href="{{ url_for('user_routes_blueprint.user_books', user_id=user_id, page=total_pages) }}">Derniers</a>
</div>
{% endif %}
</div>
{% endblock content %}
1 change: 1 addition & 0 deletions app/packages/flask_app/project/user_routes_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def user_books(user_id):
per_page=per_page,
total_pages=total_pages,
user_name=user.username,
user_id=user.id,
is_authenticated=current_user.is_authenticated,
)

Expand Down

0 comments on commit 7a5a200

Please sign in to comment.