From dfbd5e8e41e3be0d67725ce87f24cdf425db0faa Mon Sep 17 00:00:00 2001 From: femalves Date: Thu, 28 Dec 2023 22:15:08 +0000 Subject: [PATCH 1/3] fixing library count error --- biblib/views/user_view.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/biblib/views/user_view.py b/biblib/views/user_view.py index 0ca23b6..f153002 100644 --- a/biblib/views/user_view.py +++ b/biblib/views/user_view.py @@ -84,6 +84,7 @@ def get_libraries(cls, service_uid, absolute_uid, start=0, rows=None, sort_col=" .filter(Permissions.user_id == service_uid)\ .order_by(getattr(getattr(Library, sort_col), sort_order)())\ .all() + libraries_response = {'libraries_count': len(result)} if rows: rows=start+rows @@ -157,15 +158,13 @@ def get_libraries(cls, service_uid, absolute_uid, start=0, rows=None, sort_col=" elif ownership and main_permission in ['admin', 'read', 'write']: shared_with_me.append(payload) - - response = {'libraries_count': len(result)} if ownership: - response['my_libraries'] = my_libraries - response['shared_with_me'] = shared_with_me + libraries_response['my_libraries'] = my_libraries + libraries_response['shared_with_me'] = shared_with_me else: - response['libraries'] = my_libraries + libraries_response['libraries'] = my_libraries - return response + return libraries_response # Methods def get(self): From b99d1d836f7b18ae07582b4e72dd2d5d8f2c7622 Mon Sep 17 00:00:00 2001 From: femalves Date: Tue, 2 Jan 2024 21:08:15 +0000 Subject: [PATCH 2/3] changing comment and result --- biblib/views/user_view.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/biblib/views/user_view.py b/biblib/views/user_view.py index f153002..f4fe234 100644 --- a/biblib/views/user_view.py +++ b/biblib/views/user_view.py @@ -121,12 +121,11 @@ def get_libraries(cls, service_uid, absolute_uid, start=0, rows=None, sort_col=" if main_permission != 'owner': # get the owner - result = session.query(Permissions, User) \ + owner_permissions, owner = session.query(Permissions, User) \ .join(Permissions.user) \ .filter(Permissions.library_id == library.id) \ .filter(Permissions.permissions['owner'].astext.cast(Boolean).is_(True)) \ .one() - owner_permissions, owner = result owner_absolute_uid = owner.absolute_uid else: owner_absolute_uid = absolute_uid @@ -174,7 +173,7 @@ def get(self): :param start: The index of the library list to start on (int). default: 0 :param rows: The number of rows to return from the start point (int). default: None (returns all libraries) - :param sort: Library column to sort on. default: date_created (date_created, date_last_modified) + :param sort: Library column to sort on. default: date_created (date_created, date_last_modified, name) :param order: Direction sort libraries. default: desc (asc, desc) :return: list of the users libraries with the relevant information From 6e5e69be9778eac24b3b80c08aa192ec13b4c931 Mon Sep 17 00:00:00 2001 From: femalves Date: Fri, 5 Jan 2024 15:51:52 +0000 Subject: [PATCH 3/3] change variable names --- biblib/views/user_view.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/biblib/views/user_view.py b/biblib/views/user_view.py index f4fe234..eaf3589 100644 --- a/biblib/views/user_view.py +++ b/biblib/views/user_view.py @@ -79,18 +79,19 @@ def get_libraries(cls, service_uid, absolute_uid, start=0, rows=None, sort_col=" # The nested getattr calls allow us to request a column from the library model, # and then request the proper sort order from that column. with current_app.session_scope() as session: - result = session.query(Permissions, Library)\ + user_libraries = session.query(Permissions, Library)\ .join(Permissions.library)\ .filter(Permissions.user_id == service_uid)\ .order_by(getattr(getattr(Library, sort_col), sort_order)())\ .all() - libraries_response = {'libraries_count': len(result)} + + libraries_response = {'libraries_count': len(user_libraries)} if rows: rows=start+rows my_libraries = [] shared_with_me = [] - for permission, library in result[start:rows]: + for permission, library in user_libraries[start:rows]: # For this library get all the people who have permissions users = session.query(Permissions).filter_by(