Skip to content

Commit

Permalink
Merge pull request #675 from UW-GAC/bugfix/inventory-inputs-for-multi…
Browse files Browse the repository at this point in the history
…ple-studies

Fix bug where only a single study is shown for a workspace linked to multiple studies
  • Loading branch information
amstilp authored Jul 30, 2024
2 parents 8002b2c + 8126df7 commit fdbd48f
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Temporary script to create some test data.
# Run with: python manage.py shell < add_phenotype_inventory_input_example_data.py
# Run with: python manage.py shell < add_inventory_input_example_data.py

from anvil_consortium_manager.tests.factories import (
ManagedGroupFactory,
Expand Down
7 changes: 4 additions & 3 deletions primed/primed_anvil/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ def get_summary_table_data():
return data


def get_workspaces_for_phenotype_inventory():
def get_workspaces_for_inventory():
"""Get input to the primed-phenotype-inventory workflow.
This function generates the input for the "workspaces" field of the primed-phenotype-inventory workflow. Only
workspaces that have been shared with the consortium are included.
See dockstore link: https://dockstore.org/workflows/github.com/UW-GAC/primed-inventory-workflows/primed_phenotype_inventory:main?tab=info
See dockstore link: https://dockstore.org/workflows/github.com/UW-GAC/primed-inventory-workflows/primed_inventory:main?tab=info
The "workspaces" field has the format:
{
Expand Down Expand Up @@ -212,7 +212,8 @@ def get_workspaces_for_phenotype_inventory():

# Combine all querysets and process into the expected output for the AnVIL workflow.
workspaces = dbgap_workspaces.union(cdsa_workspaces).union(open_access_workspaces)

# Sort by workspace_name so that itertools.groupby works as expected.
workspaces = sorted(workspaces, key=lambda x: x["workspace_name"])
json = {}
for key, group in groupby(workspaces, lambda x: x["workspace_name"]):
study_names = [x["study_names"] if x["study_names"] else "" for x in group]
Expand Down
198 changes: 169 additions & 29 deletions primed/primed_anvil/tests/test_helpers.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions primed/primed_anvil/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,8 +1247,8 @@ def test_includes_cdsa_workspaces(self):
self.assertEqual(len(response.context_data["summary_table"].rows), 1)


class PhenotypeInventoryInputsViewTest(TestCase):
"""Tests for the PhenotypeInventoryInputsView view."""
class InventoryInputsViewTest(TestCase):
"""Tests for the InventoryInputsView view."""

def setUp(self):
"""Set up test class."""
Expand All @@ -1262,11 +1262,11 @@ def setUp(self):

def get_url(self, *args):
"""Get the url for the view being tested."""
return reverse("primed_anvil:utilities:phenotype_inventory_inputs", args=args)
return reverse("primed_anvil:utilities:inventory_inputs", args=args)

def get_view(self):
"""Return the view being tested."""
return views.PhenotypeInventoryInputsView.as_view()
return views.InventoryInputsView.as_view()

def test_view_redirect_not_logged_in(self):
"View redirects to login view when user is not logged in."
Expand Down
6 changes: 3 additions & 3 deletions primed/primed_anvil/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
utilities_patterns = (
[
path(
"phenotype_inventory_inputs/",
views.PhenotypeInventoryInputsView.as_view(),
name="phenotype_inventory_inputs",
"inventory_inputs/",
views.InventoryInputsView.as_view(),
name="inventory_inputs",
),
],
"utilities",
Expand Down
6 changes: 3 additions & 3 deletions primed/primed_anvil/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ def get_context_data(self, **kwargs):
return context


class PhenotypeInventoryInputsView(AnVILConsortiumManagerStaffViewRequired, TemplateView):
template_name = "primed_anvil/phenotype_inventory_inputs.html"
class InventoryInputsView(AnVILConsortiumManagerStaffViewRequired, TemplateView):
template_name = "primed_anvil/inventory_inputs.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["workspaces_input"] = json.dumps(helpers.get_workspaces_for_phenotype_inventory(), indent=2)
context["workspaces_input"] = json.dumps(helpers.get_workspaces_for_inventory(), indent=2)
return context
2 changes: 1 addition & 1 deletion primed/templates/anvil_consortium_manager/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<li><hr class="dropdown-divider"></li>
<li>
<a class="dropdown-item" href="{% url 'primed_anvil:utilities:phenotype_inventory_inputs' %}">Phenotype inventory</a>
<a class="dropdown-item" href="{% url 'primed_anvil:utilities:inventory_inputs' %}">Inventory inputs</a>
</li>

<li><hr class="dropdown-divider"></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2>Phenotype inventory workflow</h2>

<p>
This page creates the input for the "workspaces" field in the
<a href="https://dockstore.org/workflows/github.com/UW-GAC/primed-inventory-workflows/primed_phenotype_inventory:main?tab=info">PRIMED phenotype inventory workflow</a>.
<a href="https://dockstore.org/workflows/github.com/UW-GAC/primed-inventory-workflows/primed_inventory:main?tab=info">PRIMED phenotype inventory workflow</a>.
Copy the text in the box below and paste it into the "workspaces" field when running the workflow on AnVIL.
</p>

Expand Down

0 comments on commit fdbd48f

Please sign in to comment.