Skip to content

Commit 8a2eaa5

Browse files
[Fixes #12413] Group filter autocomplete does not work (#12414) (#12415)
(cherry picked from commit 0c827f5) Co-authored-by: mattiagiupponi <51856725+mattiagiupponi@users.noreply.github.com>
1 parent bb78275 commit 8a2eaa5

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

geonode/facets/providers/group.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def get_facet_items(
6262
logger.debug("Filtering by keys %r", keys)
6363
filters["group__id__in"] = keys
6464

65+
if topic_contains:
66+
filters["group__name__icontains"] = topic_contains
67+
6568
visible_groups = get_user_visible_groups(user=kwargs["user"])
6669

6770
q = (

geonode/facets/tests.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,3 +669,28 @@ def test_group_facet_api_call(self):
669669

670670
self.assertDictEqual(expected_response_filtered, response_dict_filtered)
671671
self.assertDictEqual(expected_response_base, response_dict_base)
672+
673+
def test_group_facets_are_filtered_by_words(self):
674+
# there are some groups and the facets return them
675+
url = f"{reverse('get_facet',args=['group'])}"
676+
677+
response = self.client.get(url)
678+
self.assertEqual(200, response.status_code, response.json())
679+
680+
self.assertTrue(response.json().get("topics", {}).get("total", 0) > 0)
681+
682+
# topic_contains with real name should return 1
683+
url = f"{reverse('get_facet',args=['group'])}?topic_contains=UserAdmin"
684+
response = self.client.get(url)
685+
686+
self.assertEqual(200, response.status_code, response.json())
687+
688+
self.assertEqual(1, response.json().get("topics", {}).get("total", 0))
689+
690+
# topic_contains with a random string to be searched for should be 0
691+
url = f"{reverse('get_facet',args=['group'])}?topic_contains=abc123scfuqbrwefbasascgiu"
692+
response = self.client.get(url)
693+
694+
self.assertEqual(200, response.status_code, response.json())
695+
696+
self.assertEqual(0, response.json().get("topics", {}).get("total", 0))

0 commit comments

Comments
 (0)