diff --git a/primed/cdsa/adapters.py b/primed/cdsa/adapters.py index 51305761..c72c975e 100644 --- a/primed/cdsa/adapters.py +++ b/primed/cdsa/adapters.py @@ -30,4 +30,7 @@ def get_extra_detail_context_data(self, workspace, request): extra_context["associated_data_prep_workspaces"] = DataPrepWorkspaceTable( associated_data_prep ) + extra_context["data_prep_active"] = associated_data_prep.filter( + dataprepworkspace__is_active=True + ).exists() return extra_context diff --git a/primed/cdsa/tests/test_views.py b/primed/cdsa/tests/test_views.py index edd1771b..130c10af 100644 --- a/primed/cdsa/tests/test_views.py +++ b/primed/cdsa/tests/test_views.py @@ -7267,6 +7267,9 @@ def test_associated_data_prep_workspaces_context_exists(self): self.client.force_login(self.user) response = self.client.get(obj.get_absolute_url()) self.assertIn("associated_data_prep_workspaces", response.context_data) + import ipdb + + ipdb.set_trace() self.assertIsInstance( response.context_data["associated_data_prep_workspaces"], DataPrepWorkspaceTable, @@ -7311,6 +7314,46 @@ def test_show_two_associated_data_prep_workspaces(self): response.context_data["associated_data_prep_workspaces"].data, ) + def test_context_data_prep_active_with_no_prep_workspace(self): + instance = factories.CDSAWorkspaceFactory.create() + self.client.force_login(self.user) + response = self.client.get(instance.get_absolute_url()) + self.assertIn("data_prep_active", response.context_data) + self.assertFalse(response.context["data_prep_active"]) + + def test_context_data_prep_active_with_one_inactive_prep_workspace(self): + instance = factories.CDSAWorkspaceFactory.create() + DataPrepWorkspaceFactory.create( + target_workspace=instance.workspace, is_active=False + ) + self.client.force_login(self.user) + response = self.client.get(instance.get_absolute_url()) + self.assertIn("data_prep_active", response.context_data) + self.assertFalse(response.context["data_prep_active"]) + + def test_context_data_prep_active_with_one_active_prep_workspace(self): + instance = factories.CDSAWorkspaceFactory.create() + DataPrepWorkspaceFactory.create( + target_workspace=instance.workspace, is_active=True + ) + self.client.force_login(self.user) + response = self.client.get(instance.get_absolute_url()) + self.assertIn("data_prep_active", response.context_data) + self.assertTrue(response.context["data_prep_active"]) + + def test_context_data_prep_active_with_one_active_one_inactive_prep_workspace(self): + instance = factories.CDSAWorkspaceFactory.create() + DataPrepWorkspaceFactory.create( + target_workspace=instance.workspace, is_active=True + ) + DataPrepWorkspaceFactory.create( + target_workspace=instance.workspace, is_active=True + ) + self.client.force_login(self.user) + response = self.client.get(instance.get_absolute_url()) + self.assertIn("data_prep_active", response.context_data) + self.assertTrue(response.context["data_prep_active"]) + class CDSAWorkspaceCreateTest(AnVILAPIMockTestMixin, TestCase): """Tests of the WorkspaceCreate view from ACM with this app's CDSAWorkspace model.""" diff --git a/primed/dbgap/adapters.py b/primed/dbgap/adapters.py index 485fb507..626a3c10 100644 --- a/primed/dbgap/adapters.py +++ b/primed/dbgap/adapters.py @@ -28,4 +28,7 @@ def get_extra_detail_context_data(self, workspace, request): extra_context["associated_data_prep_workspaces"] = DataPrepWorkspaceTable( associated_data_prep ) + extra_context["data_prep_active"] = associated_data_prep.filter( + dataprepworkspace__is_active=True + ).exists() return extra_context diff --git a/primed/dbgap/tests/test_views.py b/primed/dbgap/tests/test_views.py index c009ae37..c33fb131 100644 --- a/primed/dbgap/tests/test_views.py +++ b/primed/dbgap/tests/test_views.py @@ -1002,6 +1002,46 @@ def test_show_two_associated_data_prep_workspaces(self): response.context_data["associated_data_prep_workspaces"].data, ) + def test_context_data_prep_active_with_no_prep_workspace(self): + instance = factories.dbGaPWorkspaceFactory.create() + self.client.force_login(self.user) + response = self.client.get(instance.get_absolute_url()) + self.assertIn("data_prep_active", response.context_data) + self.assertFalse(response.context["data_prep_active"]) + + def test_context_data_prep_active_with_one_inactive_prep_workspace(self): + instance = factories.dbGaPWorkspaceFactory.create() + DataPrepWorkspaceFactory.create( + target_workspace=instance.workspace, is_active=False + ) + self.client.force_login(self.user) + response = self.client.get(instance.get_absolute_url()) + self.assertIn("data_prep_active", response.context_data) + self.assertFalse(response.context["data_prep_active"]) + + def test_context_data_prep_active_with_one_active_prep_workspace(self): + instance = factories.dbGaPWorkspaceFactory.create() + DataPrepWorkspaceFactory.create( + target_workspace=instance.workspace, is_active=True + ) + self.client.force_login(self.user) + response = self.client.get(instance.get_absolute_url()) + self.assertIn("data_prep_active", response.context_data) + self.assertTrue(response.context["data_prep_active"]) + + def test_context_data_prep_active_with_one_active_one_inactive_prep_workspace(self): + instance = factories.dbGaPWorkspaceFactory.create() + DataPrepWorkspaceFactory.create( + target_workspace=instance.workspace, is_active=True + ) + DataPrepWorkspaceFactory.create( + target_workspace=instance.workspace, is_active=True + ) + self.client.force_login(self.user) + response = self.client.get(instance.get_absolute_url()) + self.assertIn("data_prep_active", response.context_data) + self.assertTrue(response.context["data_prep_active"]) + class dbGaPWorkspaceCreateTest(AnVILAPIMockTestMixin, TestCase): """Tests of the WorkspaceCreate view from ACM with this app's dbGaPWorkspace model.""" diff --git a/primed/templates/cdsa/cdsaworkspace_detail.html b/primed/templates/cdsa/cdsaworkspace_detail.html index 046c6277..b0d2da12 100644 --- a/primed/templates/cdsa/cdsaworkspace_detail.html +++ b/primed/templates/cdsa/cdsaworkspace_detail.html @@ -81,7 +81,7 @@

-{% include "snippets/data_prep_workspace_table.html" with table=associated_data_prep_workspaces %} +{% include "snippets/data_prep_workspace_table.html" with table=associated_data_prep_workspaces is_active=data_prep_active %} {{block.super}} {% endblock after_panel %} diff --git a/primed/templates/dbgap/dbgapworkspace_detail.html b/primed/templates/dbgap/dbgapworkspace_detail.html index f5c02a2b..c71d751f 100644 --- a/primed/templates/dbgap/dbgapworkspace_detail.html +++ b/primed/templates/dbgap/dbgapworkspace_detail.html @@ -94,7 +94,7 @@

-{% include "snippets/data_prep_workspace_table.html" with table=associated_data_prep_workspaces %} +{% include "snippets/data_prep_workspace_table.html" with table=associated_data_prep_workspaces is_active=data_prep_active %} {{block.super}} {% endblock after_panel %} diff --git a/primed/templates/snippets/data_prep_workspace_table.html b/primed/templates/snippets/data_prep_workspace_table.html index 8fb638d9..cb9c9b66 100644 --- a/primed/templates/snippets/data_prep_workspace_table.html +++ b/primed/templates/snippets/data_prep_workspace_table.html @@ -7,7 +7,7 @@