Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0f048db
[Fixes #8689] Extend the ResourceBase metadata model with an opaque J…
mattiagiupponi Jan 26, 2022
20a1c14
[Fixes #8689] Fix missing resource_type for new form instances
mattiagiupponi Jan 27, 2022
95aa9c7
[Fixes #8689] Add test and UI fix for doc, maps and geoapps
mattiagiupponi Jan 27, 2022
38de0f0
[Fixes #8689] Fix flakee8 formatting
mattiagiupponi Jan 27, 2022
b2ba2c6
[Fixes #8689] Extra metadata json saved with format
mattiagiupponi Jan 27, 2022
318a2f0
[Fixes #8689] Refactor validation def, start defining endpoint for API
mattiagiupponi Jan 27, 2022
f108344
[Fixes #8689] Definition of extra-metadata endpoints for resources
mattiagiupponi Jan 27, 2022
e20c656
[Fixes #8689] Converting metadata from jsonfield to manytomany relation
mattiagiupponi Jan 28, 2022
0ba2ebd
[Fixes #8689] Fix views with new relation and prettify json on UI
mattiagiupponi Jan 28, 2022
19319a2
[Fixes #8689] Fix serializer
mattiagiupponi Jan 31, 2022
bd04373
Merge branch '3.3.x' of https://github.com/GeoNode/geonode into ISSUE…
mattiagiupponi Feb 1, 2022
f06c954
[Fixes #8689] Fix custom metadata endpoint, update metadata schema
mattiagiupponi Feb 1, 2022
43c77df
[Fixes #8689] Fix flake8 issues
mattiagiupponi Feb 1, 2022
4685630
[Fixes #8689] Remove endpoint from each resorce, keep it only on base…
mattiagiupponi Feb 1, 2022
8cb942f
[Fixes #8689] Fix broken tests
mattiagiupponi Feb 1, 2022
499ea10
[Fixes #8689] Add metadata filtering in API v1
mattiagiupponi Feb 1, 2022
bf819b4
[Fixes #8689] Add test for metadata filtering in API v1
mattiagiupponi Feb 1, 2022
17cf50e
[Fixes #8689] Fix some of broken tests
mattiagiupponi Feb 2, 2022
0d425b1
[Fixes #8689] fix flake8
mattiagiupponi Feb 2, 2022
2f197f1
[Fixes #8689] fix tests
mattiagiupponi Feb 2, 2022
d7b5c55
[Fixes #8689] removed typo on settings.py
mattiagiupponi Feb 2, 2022
a6498e2
[Fixes #8689] fix broken build
mattiagiupponi Feb 2, 2022
9a911f6
[Fixes #8689] fix minor error on filter convertion
mattiagiupponi Feb 2, 2022
e462385
[Fixes #8690] first implementation for dynamic filtering
mattiagiupponi Feb 2, 2022
810999e
[Fixes #8690] first implementation for dynamic filtering
mattiagiupponi Feb 2, 2022
cf7c4ec
[Fixes #8689] fix flake8
mattiagiupponi Feb 2, 2022
8d8480a
[Fixes #8689] Update default schema structure
mattiagiupponi Feb 2, 2022
ea5abd1
Merge branch 'ISSUE_8689' of github.com:mattiagiupponi/geonode into I…
mattiagiupponi Feb 2, 2022
b502668
[Fixes #8690] first implementation for dynamic filtering
mattiagiupponi Feb 2, 2022
73220a3
[Fixes #8690] Dynamic metadata facet filtering
mattiagiupponi Feb 3, 2022
79ae119
[Fixes #8690] Minor fix for geoapps
mattiagiupponi Feb 3, 2022
b089bf2
[Fixes #8690] Flake8 format fix
mattiagiupponi Feb 3, 2022
14abc5b
[Fixes #8690] merge with 3.3.x
mattiagiupponi Feb 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__')}
# 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})
orm_filters['f_method'] = filters['f_method'] if 'f_method' in filters else 'and'
Expand Down
53 changes: 51 additions & 2 deletions geonode/base/templatetags/base_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#
#########################################################################

from enum import Enum
import logging

from django import template
Expand All @@ -31,7 +32,7 @@
from pinax.ratings.models import Rating
from guardian.shortcuts import get_objects_for_user

from geonode.base.models import ResourceBase
from geonode.base.models import ExtraMetadata, ResourceBase
from geonode.base.bbox_utils import filter_bbox
from geonode.layers.models import Layer
from geonode.maps.models import Map
Expand All @@ -41,7 +42,9 @@
HierarchicalKeyword, Menu, MenuItem
)
from geonode.security.utils import get_visible_resources
from collections import OrderedDict
from collections import OrderedDict, Counter

from geonode.utils import get_geoapps_models

logger = logging.getLogger(__name__)

Expand All @@ -56,6 +59,13 @@
}


class FACET_TO_RESOURCE_TYPE(Enum):
layers = 'layer'
maps = 'map'
documents = 'document'
geoapps = 'geoapp'


@register.filter(name='template_trans')
def template_trans(text):
try:
Expand Down Expand Up @@ -495,3 +505,42 @@ def get_layer_count_by_services(service_id, user):
queryset=Layer.objects.filter(remote_service=service_id),
user=user
).count()


@register.simple_tag(takes_context=True)
def dynamic_metadata_filters(context):

facet_type = context.get('facet_type', 'all')

metadata_available = ExtraMetadata.objects.all()

if facet_type != 'all':
resource_type = [getattr(FACET_TO_RESOURCE_TYPE, facet_type).value]
if 'geoapp' in resource_type:
resource_type = [''.join(list(x.models)) for x in get_geoapps_models()]
metadata_available = metadata_available\
.filter(resource__polymorphic_ctype__model__in=resource_type)

if not metadata_available.exists():
return []

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

output = {}

for _cat in categories:
output[_cat] = _get_filter_by_category(_cat, metadata_available)

return output


def _get_filter_by_category(category, metadata_available):
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
18 changes: 18 additions & 0 deletions geonode/templates/search/_dynamic_metadata_filter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% load i18n %}
{% load base_tags %}
{% dynamic_metadata_filters as data %}
{% for key, values in data.items %}
<nav class="filter">
<h4><a href="#" class="toggle toggle-nav"><i class="fa fa-chevron-right"></i>{{key}}</a></h4>
<ul class="nav closed" id="dynamic_filter_{{ key|slugify }}">
{% for el in values %}
<li>
<a id="dynamic_filter_{{ el.id }}" data-value="{{ el.field_value }}" data-filter="metadata__field_value" ng-click="multiple_choice_listener($event)">
{{ el.field_label }}
<span class="badge pull-right">{{el.count}}</span>
</a>
</li>
{% endfor %}
</ul>
</nav>
{% endfor %}
1 change: 1 addition & 0 deletions geonode/templates/search/_search_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
{% if SEARCH_FILTERS.EXTENT_ENABLED %}
{% include "search/_extent_filter.html" %}
{% endif %}
{% include "search/_dynamic_metadata_filter.html" %}
{% endblock search_facet_lists %}
</div>
{% endif %}
Expand Down