Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add search functionality for models #393

Merged
merged 37 commits into from
Oct 24, 2023

Conversation

wkirdp
Copy link
Collaborator

@wkirdp wkirdp commented Sep 21, 2023

  • Define filters for Billing Projects, Managed Groups, Workspaces and Accounts lists
  • Use filters in BillingProjectList, ManagedGroupList, WorkspacesList, WorkspaceListByType, AccountList, AccountActiveList, and AccountInctiveList views.
  • Add filter forms on billingproject_list, managedgroup_list, workspace_list and account_list templates
  • Add tests

Add filter.py, define the filter for BillingProjects
Modify billingproject_list.html to include the filter form
Add BillingProjectFilter to BillingProjectList view.
Add filter to ManageGroupList view
Add the FilterSet to managedgroup_list template
Add tests
Add filter to WorkspaceList view and WorkspaceListByType view
Add filter form on workspace_list template
Add tests for WorkspaceList view and WorkspaceListByType view
Add AccountList filter to AccountList, AccountActiveList and AccountInactiveList views
Add filter form to account_list template
Add tests for  AccountList, AccountActiveList and AccountInactiveList views
@wkirdp wkirdp requested a review from amstilp September 21, 2023 01:04
@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Merging #393 (d29fdb4) into main (63ba24c) will increase coverage by 0.00%.
Report is 2 commits behind head on main.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##             main     #393    +/-   ##
========================================
  Coverage   99.82%   99.82%            
========================================
  Files         119      121     +2     
  Lines       22335    22802   +467     
========================================
+ Hits        22295    22762   +467     
  Misses         40       40            
Files Coverage Δ
anvil_consortium_manager/__init__.py 100.00% <100.00%> (ø)
anvil_consortium_manager/adapters/account.py 100.00% <100.00%> (ø)
anvil_consortium_manager/adapters/default.py 100.00% <100.00%> (ø)
anvil_consortium_manager/filters.py 100.00% <100.00%> (ø)
anvil_consortium_manager/forms.py 100.00% <100.00%> (ø)
...mplates/anvil_consortium_manager/account_list.html 100.00% <100.00%> (ø)
.../anvil_consortium_manager/billingproject_list.html 100.00% <100.00%> (ø)
...es/anvil_consortium_manager/managedgroup_list.html 100.00% <100.00%> (ø)
...lates/anvil_consortium_manager/workspace_list.html 100.00% <100.00%> (ø)
anvil_consortium_manager/tests/test_adapters.py 100.00% <100.00%> (ø)
... and 5 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@amstilp amstilp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I made some comments about things to change, mostly with tests, as well as some info about using the AccountAdapter. I'm also working on a way to make the filter form display more nicely on the page, so I'll see where I get with that.

anvil_consortium_manager/filters.py Show resolved Hide resolved
anvil_consortium_manager/tests/test_views.py Outdated Show resolved Hide resolved
self.assertEqual(response.status_code, 200)
self.assertIn("table", response.context_data)
self.assertEqual(len(response.context_data["table"].rows), 2)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you have the AccountAdapter included, you'll want to add a test that checks filtering using the custom fields that a user has specified in the adapter. See the AccountAutocomplete tests for an example. This will requiring modifying the TestAccountAdapter in anvil_consortium_manager/tests/test_app/adapters.py

anvil_consortium_manager/tests/test_views.py Outdated Show resolved Hide resolved
anvil_consortium_manager/tests/test_views.py Outdated Show resolved Hide resolved
anvil_consortium_manager/tests/test_views.py Show resolved Hide resolved
anvil_consortium_manager/tests/test_views.py Show resolved Hide resolved
anvil_consortium_manager/tests/test_views.py Outdated Show resolved Hide resolved
self.assertEqual(response.status_code, 200)
self.assertIn("table", response.context_data)
self.assertEqual(len(response.context_data["table"].rows), 2)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for a user-specified workspace type - see the test_adapter method in this test case for an example. You'll want to test that it only finds the workspace of the correct type, not the workspace of the other type, even if both have a name that matches your querystring.

setup.cfg Outdated Show resolved Hide resolved
This custom form uses the crispy_form package's layout objects to
manipulate the placement and apperance of forms. In particular, it
displays the form fields on a single line, including the submit
button, with floating labels. This takes up a smaller footprint
and is less intrusive compared to the previous standard way of
displaying the form.
@amstilp
Copy link
Contributor

amstilp commented Sep 22, 2023

@wkirdp I played around with the filter form to get something that is a little less intrusive. Please see the changes I made to BillingProjectFilter and the billingproject_list.html template, and make the same changes for the other filters and list templates.

wkirdp and others added 11 commits September 22, 2023 12:39
Pass in query parameter instead of manually appending to the url
Modify tests to be testing more specific things (exact match,
contains match, icontains match, multiple objects). For some views,
also check that other objects are excluded when appropriate (eg that
inactive accounts do not show up in the active account view filter).
This is the same form that was implemented for BillingProjectListFilter.
Missed this one when I was updating the other templates.
This lets the user customize the filterset_class used in the
AccountList view. (Example: a project using this app wants to allow
people to search on both the account email and the user name
associated with the account.)
Add an AccountAdapterMixin, which sets the adapter attribute of
the view class. It also contains reusable methods to get information
from the adapter (e.g., the list class and the filterset class).
Use this mixin for all of the AccountList views, which uses the
list_filterset_class defined by whichever account adapter is set
by the project settings file.
setup.cfg Outdated
@@ -35,6 +35,7 @@ install_requires =
google-auth >= 2.6
fontawesomefree >= 6.1
django-autocomplete-light >= 3.9
django-filter > 2.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this version is correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wkirdp Can you look into this? Did you mean > 23.0? >=23.0?

Copy link
Collaborator Author

@wkirdp wkirdp Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amstilp I pinned it to 23.2 and you said maybe not to pin to such a high version. Maybe just >2.0. Did I misunderstand? (After version 2.4, it jumped to 21.1, then 22.1 and 23.1)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I saw version 23.2 in requirements/base.txt and >2 in setup.cfg and thought it was unintentional. Ignore if that version makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wkirdp No, you didn't misunderstand. Best practice is to pin to the lowest working version. I did a couple tests with different versions of django-filter, and the tests fail with versions < 2.3.0. I switched the requirement in setup.cfg to require django-filter >= 2.3.0.

Mostly this includes setting the PIP_NO_CACHE_DIR environment
variable. I'm not sure why it was working in the other branch, or
if it will definitely fix it here.
The previous commit used the working CI file, but I forgot to add
the corresponding tox file. Hopefully this works.
@amstilp
Copy link
Contributor

amstilp commented Oct 24, 2023

CI issues seem to be intermittent and solved by retrying tox runs using the retry github action. The failures happen more often when there is no cache. It does not seem to be anything in the code.

@amstilp amstilp merged commit 6ad526f into main Oct 24, 2023
@amstilp amstilp deleted the feature/add-search-functionality-for-models branch October 25, 2023 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants