Skip to content

Commit 1e05f3f

Browse files
committed
show collection icon for collection parent
1 parent 8ccb3c3 commit 1e05f3f

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

ckanext/datagovtheme/helpers.py

+19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import pkg_resources
1111

12+
import ckan.logic as logic
1213
from ckan import plugins as p, model
1314
from ckan.lib import base, helpers as h
1415
from ckan.plugins.toolkit import asbool, config
@@ -670,6 +671,24 @@ def is_tagged_ngda(pkg_dict):
670671
return False
671672

672673

674+
def is_collection_parent(pkg_dict):
675+
'''Returns True if the package is a collection parent
676+
this relies on the searching with collection_info fq
677+
collection_info is handled in geodatagov'''
678+
sid = get_pkg_dict_extra(pkg_dict, 'harvest_source_id', None)
679+
pid = get_pkg_dict_extra(pkg_dict, 'identifier', None)
680+
package_search = logic.get_action('package_search')
681+
search_params = {
682+
'fq': f'collection_info:"{sid} {pid}"'
683+
}
684+
base_results = package_search(
685+
{'ignore_auth': True},
686+
search_params
687+
)
688+
689+
return asbool(base_results['results'])
690+
691+
673692
# TODO can we drop this dependency on ckanext-harvest? Can this be moved to ckanext-harvest? geodatagov?
674693
def get_pkg_dict_extra(pkg_dict, key, default=None):
675694
'''Override the CKAN core helper to add rolled up extras

ckanext/datagovtheme/plugin.py

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def get_helpers(self):
8989
'datagovtheme_get_reference_date': datagovtheme_helpers.get_reference_date,
9090
'datagovtheme_get_responsible_party': datagovtheme_helpers.get_responsible_party,
9191
'is_tagged_ngda': datagovtheme_helpers.is_tagged_ngda,
92+
'is_collection_parent': datagovtheme_helpers.is_collection_parent,
9293
'render_datetime_datagov': datagovtheme_helpers.render_datetime_datagov,
9394
'get_harvest_object_formats': datagovtheme_helpers.get_harvest_object_formats,
9495
'get_bureau_info': datagovtheme_helpers.get_bureau_info,

ckanext/datagovtheme/templates/snippets/package_item.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h3 class="dataset-heading" pkg_id="{{ package.id }}">
4343
</span>
4444
{% endif %}
4545

46-
{% if h.get_pkg_dict_extra(package, 'collection_metadata', '') %}
46+
{% if h.is_collection_parent(package) %}
4747
<span class="dataset-collection label {{ 'label-default' }}">
4848
<i class="icon-collection"></i>
4949
{{ _('Collection') }}

dev-requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ factory-boy>=2
33
flake8
44
mock
55
pytest
6-
pytest-ckan
76
pytest-cov

0 commit comments

Comments
 (0)