Skip to content

Commit

Permalink
Allows to filter datasets on resource type
Browse files Browse the repository at this point in the history
  • Loading branch information
noirbizarre committed Aug 23, 2018
1 parent 9a2fcaf commit b3dbd88
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,7 +11,11 @@

- Only display temporal coverage years on cards and search results [#1833](https://github.com/opendatateam/udata/pull/1833)
- Prevent front views from downloading `swagger.json` [#1838](https://github.com/opendatateam/udata/pull/1838)
<<<<<<< HEAD
- Improved upload error handling: deduplicate notifications, localized generic error message, sentry identifier... [#1842](https://github.com/opendatateam/udata/pull/1842)
=======
- Allows to filter datasets on resource `type` (needs reindexing) [#1848](https://github.com/opendatateam/udata/pull/1848)
>>>>>>> Allows to filter datasets on resource type
### Breaking changes

Expand Down
9 changes: 8 additions & 1 deletion udata/core/dataset/search.py
Expand Up @@ -8,7 +8,7 @@
from udata.i18n import lazy_gettext as _
from udata.core.site.models import current_site
from udata.models import (
Dataset, Organization, License, User, GeoZone
Dataset, Organization, License, User, GeoZone, RESOURCE_TYPES
)
from udata.search import (
ModelSearchAdapter, i18n_analyzer, metrics_mapping_for, register,
Expand Down Expand Up @@ -58,6 +58,10 @@ def dataset_badge_labelizer(kind):
return Dataset.__badges__.get(kind, '')


def resource_type_labelizer(value):
return RESOURCE_TYPES.get(value, value)


@register
class DatasetSearch(ModelSearchAdapter):
model = Dataset
Expand Down Expand Up @@ -140,6 +144,8 @@ class Meta:
'granularity': TermsFacet(field='granularity',
labelizer=granularity_labelizer),
'format': TermsFacet(field='resources.format'),
'resource_type': TermsFacet(field='resources.type',
labelizer=resource_type_labelizer),
'reuses': RangeFacet(field='metrics.reuses',
ranges=[('none', (None, 1)),
('few', (1, 5)),
Expand Down Expand Up @@ -205,6 +211,7 @@ def serialize(cls, dataset):
'title': r.title,
'description': r.description,
'format': r.format,
'type': r.type,
}
for r in dataset.resources],
'format_suggest': [r.format.lower()
Expand Down
3 changes: 3 additions & 0 deletions udata/templates/dataset/search-labels.html
Expand Up @@ -22,6 +22,9 @@
labelize=datasets.label_func('granularity')
) }}
{{ s.filter_label('format', _('Format'), ficon('fa-file')) }}
{{ s.filter_label('resource_type', _('Resource type'), ficon('fa-file-o'),
labelize=datasets.label_func('resource_type')
) }}
{{ s.filter_label('reuses', _('Reuses'), ficon('fa-retweet'),
labelize=datasets.label_func('reuses')
) }}
Expand Down

0 comments on commit b3dbd88

Please sign in to comment.