mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
16261 fix graphql lookup for MultiValueCharFilter fields (#16354)
* 16261 fix graphql lookup for MultiValueCharFilter fields * 16261 fix graphql lookup for MultiValueCharFilter fields * 16261 fixup test * 16261 fixup test * Omit redundant assignment --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
parent
fdad59c8cc
commit
8e48e939aa
@ -649,7 +649,7 @@ class IPAddressTest(APIViewTestCases.APIViewTestCase):
|
||||
'description': 'New description',
|
||||
}
|
||||
graphql_filter = {
|
||||
'address': '192.168.0.1/24',
|
||||
'address': {'lookup': 'i_exact', 'value': '192.168.0.1/24'},
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
@ -23,8 +23,9 @@ def map_strawberry_type(field):
|
||||
elif isinstance(field, MultiValueArrayFilter):
|
||||
pass
|
||||
elif isinstance(field, MultiValueCharFilter):
|
||||
should_create_function = True
|
||||
attr_type = List[str] | None
|
||||
# Note: Need to use the legacy FilterLookup from filters, not from
|
||||
# strawberry_django.FilterLookup as we currently have USE_DEPRECATED_FILTERS
|
||||
attr_type = strawberry_django.filters.FilterLookup[str] | None
|
||||
elif isinstance(field, MultiValueDateFilter):
|
||||
attr_type = auto
|
||||
elif isinstance(field, MultiValueDateTimeFilter):
|
||||
|
@ -493,10 +493,18 @@ class APIViewTestCases:
|
||||
|
||||
def _build_filtered_query(self, name, **filters):
|
||||
"""
|
||||
Create a filtered query: i.e. ip_address_list(filters: {address: "1.1.1.1/24"}){.
|
||||
Create a filtered query: i.e. device_list(filters: {name: {i_contains: "akron"}}){.
|
||||
"""
|
||||
# TODO: This should be extended to support AND, OR multi-lookups
|
||||
if filters:
|
||||
filter_string = ', '.join(f'{k}: "{v}"' for k, v in filters.items())
|
||||
for field_name, params in filters.items():
|
||||
lookup = params['lookup']
|
||||
value = params['value']
|
||||
if lookup:
|
||||
query = f'{{{lookup}: "{value}"}}'
|
||||
filter_string = f'{field_name}: {query}'
|
||||
else:
|
||||
filter_string = f'{field_name}: "{value}"'
|
||||
filter_string = f'(filters: {{{filter_string}}})'
|
||||
else:
|
||||
filter_string = ''
|
||||
|
Loading…
Reference in New Issue
Block a user