From abd14bf501d3f7a7aac4823c83c8b51615f80d64 Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Fri, 23 Jun 2023 10:20:06 +0300 Subject: [PATCH] mobile: my library shows less books than desktop #212 --- .../book/components/book_list_item.html | 2 +- app/templates/user/profile.html | 2 +- app/views/user.py | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/templates/book/components/book_list_item.html b/app/templates/book/components/book_list_item.html index 82a6017..76bb328 100644 --- a/app/templates/book/components/book_list_item.html +++ b/app/templates/book/components/book_list_item.html @@ -9,7 +9,7 @@ {% endif %} - {% if not hide_contributing_label and book.user_id != current_user.id %} + {% if not hide_contributing_label and book.user_id != current_user.id and current_user in book.contributors_users %} Contributing {% endif %} diff --git a/app/templates/user/profile.html b/app/templates/user/profile.html index 75be908..ca34f18 100644 --- a/app/templates/user/profile.html +++ b/app/templates/user/profile.html @@ -48,7 +48,7 @@
diff --git a/app/views/user.py b/app/views/user.py index 60b0af8..18e1c9e 100644 --- a/app/views/user.py +++ b/app/views/user.py @@ -71,11 +71,25 @@ def profile(user_id: int): interpretations: m.Interpretation = m.Interpretation.query.filter_by( user_id=user_id ) + books: m.Interpretation = ( + db.session.query( + m.Book, + ) + .join(m.BookContributor, m.BookContributor.book_id == m.Book.id, full=True) + .filter( + or_( + m.Book.user_id == user_id, + m.BookContributor.user_id == user_id, + ), + m.Book.is_deleted == False, # noqa: E712 + ) + ).all() + if not user: log(log.ERROR, "Not found user by id : [%s]", user_id) flash("Cannot find user data", "danger") return render_template( - "user/profile.html", user=user, interpretations=interpretations + "user/profile.html", user=user, interpretations=interpretations, books=books )