Skip to content

Commit

Permalink
Merge pull request #300 from UW-GAC/feature/acm-v0.19
Browse files Browse the repository at this point in the history
Use ACM v0.19
  • Loading branch information
amstilp authored Oct 27, 2023
2 parents 7638b63 + c9fdefc commit 4b83f4f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ gregor_django/media/

### test db
gregor_django.db
*.db

### dbbackups
dbbackups/



1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
]
THIRD_PARTY_APPS = [
"crispy_forms",
"crispy_bootstrap5",
"allauth",
"allauth.account",
"allauth.socialaccount",
Expand Down
11 changes: 10 additions & 1 deletion gregor_django/gregor_anvil/adapters.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from anvil_consortium_manager.adapters.account import BaseAccountAdapter
from anvil_consortium_manager.adapters.workspace import BaseWorkspaceAdapter
from anvil_consortium_manager.forms import WorkspaceForm
from django.db.models import Q

from . import forms, models, tables
from . import filters, forms, models, tables


class AccountAdapter(BaseAccountAdapter):
"""Custom account adapter for PRIMED."""

list_table_class = tables.AccountTable
list_filterset_class = filters.AccountListFilter

def get_autocomplete_queryset(self, queryset, q):
"""Filter to Accounts where the email or the associated user name matches the query `q`."""
Expand Down Expand Up @@ -36,6 +38,7 @@ class UploadWorkspaceAdapter(BaseWorkspaceAdapter):
list_table_class = tables.UploadWorkspaceTable
workspace_data_model = models.UploadWorkspace
workspace_data_form_class = forms.UploadWorkspaceForm
workspace_form_class = WorkspaceForm
workspace_detail_template_name = "gregor_anvil/uploadworkspace_detail.html"

def get_autocomplete_queryset(self, queryset, q, forwarded={}):
Expand Down Expand Up @@ -66,6 +69,7 @@ class ExampleWorkspaceAdapter(BaseWorkspaceAdapter):
workspace_data_model = models.ExampleWorkspace
workspace_data_form_class = forms.ExampleWorkspaceForm
workspace_detail_template_name = "anvil_consortium_manager/workspace_detail.html"
workspace_form_class = WorkspaceForm


class TemplateWorkspaceAdapter(BaseWorkspaceAdapter):
Expand All @@ -78,6 +82,7 @@ class TemplateWorkspaceAdapter(BaseWorkspaceAdapter):
workspace_data_model = models.TemplateWorkspace
workspace_data_form_class = forms.TemplateWorkspaceForm
workspace_detail_template_name = "gregor_anvil/templateworkspace_detail.html"
workspace_form_class = WorkspaceForm


class CombinedConsortiumDataWorkspaceAdapter(BaseWorkspaceAdapter):
Expand All @@ -92,6 +97,7 @@ class CombinedConsortiumDataWorkspaceAdapter(BaseWorkspaceAdapter):
workspace_detail_template_name = (
"gregor_anvil/combinedconsortiumdataworkspace_detail.html"
)
workspace_form_class = WorkspaceForm


class ReleaseWorkspaceAdapter(BaseWorkspaceAdapter):
Expand All @@ -104,6 +110,7 @@ class ReleaseWorkspaceAdapter(BaseWorkspaceAdapter):
workspace_data_model = models.ReleaseWorkspace
workspace_data_form_class = forms.ReleaseWorkspaceForm
workspace_detail_template_name = "gregor_anvil/releaseworkspace_detail.html"
workspace_form_class = WorkspaceForm


class DCCProcessingWorkspaceAdapter(BaseWorkspaceAdapter):
Expand All @@ -116,6 +123,7 @@ class DCCProcessingWorkspaceAdapter(BaseWorkspaceAdapter):
workspace_data_model = models.DCCProcessingWorkspace
workspace_data_form_class = forms.DCCProcessingWorkspaceForm
workspace_detail_template_name = "gregor_anvil/dccprocessingworkspace_detail.html"
workspace_form_class = WorkspaceForm


class DCCProcessedDataWorkspaceAdapter(BaseWorkspaceAdapter):
Expand All @@ -130,3 +138,4 @@ class DCCProcessedDataWorkspaceAdapter(BaseWorkspaceAdapter):
workspace_detail_template_name = (
"gregor_anvil/dccprocesseddataworkspace_detail.html"
)
workspace_form_class = WorkspaceForm
10 changes: 10 additions & 0 deletions gregor_django/gregor_anvil/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from anvil_consortium_manager.forms import FilterForm
from anvil_consortium_manager.models import Account
from django_filters import FilterSet


class AccountListFilter(FilterSet):
class Meta:
model = Account
fields = {"email": ["icontains"], "user__name": ["icontains"]}
form = FilterForm
28 changes: 28 additions & 0 deletions gregor_django/gregor_anvil/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,34 @@ def test_view_with_two_objects(self):
self.assertEqual(len(response.context_data["table"].rows), 2)


class AccountListTest(TestCase):
def setUp(self):
"""Set up test class."""
self.factory = RequestFactory()
# Create a user with both view and edit permission.
self.user = User.objects.create_user(username="test", password="test")
self.user.user_permissions.add(
Permission.objects.get(
codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME
)
)

def test_filter_by_name(self):
"""Filtering by name works as expected."""
user = UserFactory.create(name="First Last")
account = acm_factories.AccountFactory.create(user=user)
other_account = acm_factories.AccountFactory.create(verified=True)
self.client.force_login(self.user)
response = self.client.get(
reverse("anvil_consortium_manager:accounts:list"),
{"user__name__icontains": "First"},
)
self.assertIn("table", response.context_data)
self.assertEqual(len(response.context_data["table"].rows), 1)
self.assertIn(account, response.context_data["table"].data)
self.assertNotIn(other_account, response.context_data["table"].data)


class UploadWorkspaceDetailTest(TestCase):
"""Tests of the anvil_consortium_manager WorkspaceDetail view using the UploadWorkspace adapter."""

Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ django-login-required-middleware==0.8.0 # https://github.com/CleitonDeLima/djang
django-dbbackup==4.0.1 # https://github.com/jazzband/django-dbbackup
django-extensions==3.2.1 # https://github.com/django-extensions/django-extensions

git+https://github.com/UW-GAC/django-anvil-consortium-manager.git@v0.17
git+https://github.com/UW-GAC/django-anvil-consortium-manager.git@v0.19

# Simple history - model history tracking
django-simple-history==3.1.1 # For tracking history
Expand Down

0 comments on commit 4b83f4f

Please sign in to comment.