Skip to content

Commit

Permalink
[Fixes GeoNode#8690] first implementation for dynamic filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed Feb 2, 2022
1 parent ea5abd1 commit b502668
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ 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']})
_metadata = {f"metadata__{_k}": _v for _k, _v in filters.items() if _k.startswith('metadata__')}

_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})
orm_filters['f_method'] = filters['f_method'] if 'f_method' in filters else 'and'
Expand Down
6 changes: 3 additions & 3 deletions geonode/base/templatetags/base_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def dynamic_metadata_filters(context):
if not metadata_available.exists():
return []

categories = metadata_available.values_list('metadata__category', flat=True).distinct()
categories = metadata_available.values_list('metadata__filter_header', flat=True).distinct()

output = {}

Expand All @@ -531,6 +531,6 @@ def dynamic_metadata_filters(context):

def _get_filter_by_category(category, metadata_available):
metadata_for_category = metadata_available.filter(
metadata__category=category
)
metadata__filter_header=category
).distinct()
return [_el.metadata for _el in metadata_for_category]
26 changes: 13 additions & 13 deletions geonode/templates/search/_dynamic_metadata_filter.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{% load i18n %}
{% load base_tags %}
<div id="dynamic_filters">
{% dynamic_metadata_filters as data %}
{% for key, values in data.items %}
<h4><a href="#" class="toggle toggle-nav"><i class="fa fa-chevron-down"></i>{{key}}</a></h4>
<ul class="nav closed" id="dynamic_filter_{{ key }}">
{% for el in values %}
<li>
<a id="dynamic_filter_{{ el.id }}" data-value="{{ el.value }}" data-filter="metadata__name" ng-click="multiple_choice_listener($event)">
{{ el.name }}
</a>
</li>
{% endfor %}
</ul>
{% endfor %}
</div>
<nav class="filter">
<h4><a href="#" class="toggle toggle-nav"><i class="fa fa-chevron-down"></i>{{key}}</a></h4>
<ul class="nav closed" id="dynamic_filter_{{ key }}">
{% for el in values %}
<li>
<a id="dynamic_filter_{{ el.field_name }}" data-value="{{ el.field_value }}" data-filter="metadata__field_value" ng-click="multiple_choice_listener($event)">
{{ el.field_label }}
</a>
</li>
{% endfor %}
</ul>
</nav>
{% endfor %}

0 comments on commit b502668

Please sign in to comment.