From 2ed8a28910d031b7015bab46744653a4e55148db Mon Sep 17 00:00:00 2001 From: Juan Puerto <=> Date: Tue, 7 Jan 2025 13:48:11 -0500 Subject: [PATCH] Views: Include workspace details in the response --- src/user_workspaces_server/models.py | 2 -- .../views/shared_workspace_view.py | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/user_workspaces_server/models.py b/src/user_workspaces_server/models.py index d2b4875..e208cf3 100644 --- a/src/user_workspaces_server/models.py +++ b/src/user_workspaces_server/models.py @@ -130,8 +130,6 @@ def get_query_param_fields(): @staticmethod def get_dict_fields(): return [ - "original_workspace_id", - "shared_workspace_id", "is_accepted", "last_params", "last_job_type", diff --git a/src/user_workspaces_server/views/shared_workspace_view.py b/src/user_workspaces_server/views/shared_workspace_view.py index 27af289..485a0e2 100644 --- a/src/user_workspaces_server/views/shared_workspace_view.py +++ b/src/user_workspaces_server/views/shared_workspace_view.py @@ -38,15 +38,31 @@ def get(self, request, shared_workspace_id=None): original_workspaces = original_workspaces.filter(**{key: params[key]}) shared_workspaces = shared_workspaces.filter(**{key: params[key]}) - dict_fields = models.SharedWorkspaceMapping.get_dict_fields() + shared_workspace_dict_fields = models.SharedWorkspaceMapping.get_dict_fields() - original_workspaces = list(original_workspaces.all().values(*dict_fields)) - shared_workspaces = list(shared_workspaces.all().values(*dict_fields)) + workspace_dict_fields = [ + "id", + "name", + "description", + "user_id__first_name", + "user_id__last_name", + ] + + shared_workspace_dict_fields.extend( + [ + prefix + dict_field + for prefix in ["original_workspace_id__", "shared_workspace_id__"] + for dict_field in workspace_dict_fields + ] + ) + + original_workspaces = list(original_workspaces.all().values(*shared_workspace_dict_fields)) + shared_workspaces = list(shared_workspaces.all().values(*shared_workspace_dict_fields)) response = { "message": "Successful.", "success": True, - "data": {"sent": [], "received": []}, + "data": {"original_workspaces": [], "shared_workspaces": []}, } if original_workspaces or shared_workspaces: