Skip to content

Commit

Permalink
[Fixes #7245] Text filter is broken (#7249) (#7259)
Browse files Browse the repository at this point in the history
Co-authored-by: Giovanni Allegri <[email protected]>

Co-authored-by: Alessio Fabiani <[email protected]>
Co-authored-by: Giovanni Allegri <[email protected]>
  • Loading branch information
3 people authored Apr 8, 2021
1 parent 7be9733 commit 1f2f80c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def apply_filters(self, request, applicable_filters):
types = applicable_filters.pop('type', None)
extent = applicable_filters.pop('extent', None)
keywords = applicable_filters.pop('keywords__slug__in', None)
metadata_only = applicable_filters.pop('metadata_only', False)
filtering_method = applicable_filters.pop('f_method', 'and')
if filtering_method == 'or':
filters = Q()
Expand Down Expand Up @@ -245,7 +246,7 @@ def apply_filters(self, request, applicable_filters):
Q(owner__username__iexact=str(user))))
else:
filtered = filtered.exclude(Q(dirty_state=True))
return filtered
return filtered.filter(metadata_only=metadata_only)

def filter_published(self, queryset, request):
filter_set = get_visible_resources(
Expand Down
8 changes: 8 additions & 0 deletions geonode/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ def to_date(val):
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 0)

def test_extended_text_filter(self):
"""Test that the extended text filter works as expected"""
filter_url = f"{self.list_url}?title__icontains=layer2&abstract__icontains=layer2&purpose__icontains=layer2&f_method=or"

resp = self.api_client.get(filter_url)
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), 1)


# noinspection DuplicatedCode
@override_settings(API_LOCKDOWN=True)
Expand Down

0 comments on commit 1f2f80c

Please sign in to comment.