diff --git a/geonode/api/resourcebase_api.py b/geonode/api/resourcebase_api.py index e219bfb3d0b..ce9cc9adf97 100644 --- a/geonode/api/resourcebase_api.py +++ b/geonode/api/resourcebase_api.py @@ -169,7 +169,7 @@ def build_filters(self, filters=None, ignore_bad_filters=False, **kwargs): orm_filters.update({'polymorphic_ctype__model__in': [filt.lower() for filt in filters.getlist('app_type__in')]}) if 'extent' in filters: orm_filters.update({'extent': filters['extent']}) - + # getting metadata filters _metadata = {f"metadata__{k}__in": filters.getlist(k) for k in filter(lambda x: x.startswith('metadata__'), filters)} if _metadata: orm_filters.update({"metadata_filters": _metadata}) diff --git a/geonode/base/templatetags/base_tags.py b/geonode/base/templatetags/base_tags.py index 8f8bf1fc117..9f441c689a2 100644 --- a/geonode/base/templatetags/base_tags.py +++ b/geonode/base/templatetags/base_tags.py @@ -43,7 +43,7 @@ HierarchicalKeyword, Menu, MenuItem ) from geonode.security.utils import get_visible_resources -from collections import OrderedDict +from collections import OrderedDict, Counter logger = logging.getLogger(__name__) @@ -530,7 +530,12 @@ def dynamic_metadata_filters(context): return output def _get_filter_by_category(category, metadata_available): - metadata_for_category = metadata_available.filter( - metadata__filter_header=category - ).distinct() - return [_el.metadata for _el in metadata_for_category] + metadata_for_category = metadata_available\ + .filter(metadata__filter_header=category) + + counters = Counter(metadata_for_category.values_list('metadata__field_name', 'metadata__field_value')) + out = [] + for _el in metadata_for_category.distinct("metadata__field_name", "metadata__field_value"): + cnt = counters.get((_el.metadata['field_name'], _el.metadata['field_value']), 0) + out.append({**{"id": _el.id, "count": cnt}, **_el.metadata}) + return out diff --git a/geonode/templates/search/_dynamic_metadata_filter.html b/geonode/templates/search/_dynamic_metadata_filter.html index 6ddea329b35..252c4fa9ecb 100644 --- a/geonode/templates/search/_dynamic_metadata_filter.html +++ b/geonode/templates/search/_dynamic_metadata_filter.html @@ -3,12 +3,13 @@ {% dynamic_metadata_filters as data %} {% for key, values in data.items %}