-
Notifications
You must be signed in to change notification settings - Fork 0
Better UI for Device Group admin (v1) #395
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
Open
chrisdoehring
wants to merge
6
commits into
main
Choose a base branch
from
gundi-4725-v1-devicegroups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7029d81
feat: friendly destination selector in DeviceGroup pages.
chrisdoehring b03de36
Remove debug print statements from DeviceGroupManagementUpdateView
cursoragent ca4d542
fix: updates from PR review comments.
chrisdoehring 8b80965
Merge branch 'gundi-4725-v1-devicegroups' of github.com:PADAS/cdip in…
chrisdoehring 7e48d1c
fix: coding error in initializing bridge form.
chrisdoehring d3da520
fix: bridge integration type swap behavior
chrisdoehring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,14 +178,51 @@ class DeviceFilter(django_filters.FilterSet): | |
| empty_label=_("Types"), | ||
| ) | ||
|
|
||
| search = django_filters.CharFilter(method='filter_search', label='Search') | ||
|
|
||
| class Meta: | ||
| model = Device | ||
| fields = ( | ||
| "organization", | ||
| "inbound_config_type", | ||
| "external_id", | ||
| "search", | ||
| ) | ||
|
|
||
| def filter_search(self, queryset, name, value): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternative implementation: Use rest_framework.DjangoFilterBackend + |
||
| """ | ||
| Search across inbound_configuration.name, name, external_id, owner.name, | ||
| inbound_configuration.default_devicegroup.name, and inbound_configuration.type.name fields | ||
| """ | ||
| if not value: | ||
| return queryset | ||
|
|
||
| # Create a Q object for OR conditions | ||
| from django.db.models import Q | ||
|
|
||
| # Search in inbound_configuration.name | ||
| config_name_q = Q(inbound_configuration__name__icontains=value) | ||
|
|
||
| # Search in device name | ||
| name_q = Q(name__icontains=value) | ||
|
|
||
| # Search in external_id | ||
| external_id_q = Q(external_id__icontains=value) | ||
|
|
||
| # Search in owner.name | ||
| owner_q = Q(inbound_configuration__owner__name__icontains=value) | ||
|
|
||
| # Search in inbound_configuration.default_devicegroup.name | ||
| devicegroup_q = Q(inbound_configuration__default_devicegroup__name__icontains=value) | ||
|
|
||
| # Search in inbound_configuration.type.name | ||
| type_name_q = Q(inbound_configuration__type__name__icontains=value) | ||
|
|
||
| # Combine all search conditions with OR | ||
| search_q = config_name_q | name_q | external_id_q | owner_q | devicegroup_q | type_name_q | ||
|
|
||
| return queryset.filter(search_q).distinct() | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| # this can appropriately update the ui filter elements | ||
| # check for stored values and set form values accordingly | ||
|
|
@@ -203,7 +240,7 @@ def qs(self): | |
| self.request.session["owner_filter"] = self.data["organization"] | ||
| if not IsGlobalAdmin.has_permission(None, self.request, None): | ||
| return IsOrganizationMember.filter_queryset_for_user( | ||
| qs, self.request.user, "owner__name" | ||
| qs, self.request.user, "inbound_configuration__owner__name" | ||
| ) | ||
| if "owner_filter" in self.request.session: | ||
| return qs.filter( | ||
|
|
@@ -344,10 +381,38 @@ def qs(self): | |
|
|
||
| class BridgeIntegrationFilter(django_filters.FilterSet): | ||
| enabled = django_filters.BooleanFilter(widget=CustomBooleanWidget) | ||
| search = django_filters.CharFilter(method='filter_search', label='Search') | ||
|
|
||
| class Meta: | ||
| model = BridgeIntegration | ||
| fields = ("enabled",) | ||
| fields = ("enabled", "search") | ||
|
|
||
| def filter_search(self, queryset, name, value): | ||
| """ | ||
| Search across owner.name, name, state, and additional fields | ||
| """ | ||
| if not value: | ||
| return queryset | ||
|
|
||
| # Create a Q object for OR conditions | ||
| from django.db.models import Q | ||
|
|
||
| # Search in owner.name | ||
| owner_q = Q(owner__name__icontains=value) | ||
|
|
||
| # Search in name field | ||
| name_q = Q(name__icontains=value) | ||
|
|
||
| # Search in state JSON field (as text) | ||
| state_q = Q(state__icontains=value) | ||
|
|
||
| # Search in additional JSON field (as text) | ||
| additional_q = Q(additional__icontains=value) | ||
|
|
||
| # Combine all search conditions with OR | ||
| search_q = owner_q | name_q | state_q | additional_q | ||
|
|
||
| return queryset.filter(search_q).distinct() | ||
|
|
||
|
|
||
| class CharInFilter(django_filters_rest.BaseInFilter, django_filters_rest.CharFilter): | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for fixing those