Commit 1e05f3f 1 parent 8ccb3c3 commit 1e05f3f Copy full SHA for 1e05f3f
File tree 4 files changed +21
-2
lines changed
4 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 9
9
10
10
import pkg_resources
11
11
12
+ import ckan .logic as logic
12
13
from ckan import plugins as p , model
13
14
from ckan .lib import base , helpers as h
14
15
from ckan .plugins .toolkit import asbool , config
@@ -670,6 +671,24 @@ def is_tagged_ngda(pkg_dict):
670
671
return False
671
672
672
673
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
+
673
692
# TODO can we drop this dependency on ckanext-harvest? Can this be moved to ckanext-harvest? geodatagov?
674
693
def get_pkg_dict_extra (pkg_dict , key , default = None ):
675
694
'''Override the CKAN core helper to add rolled up extras
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ def get_helpers(self):
89
89
'datagovtheme_get_reference_date' : datagovtheme_helpers .get_reference_date ,
90
90
'datagovtheme_get_responsible_party' : datagovtheme_helpers .get_responsible_party ,
91
91
'is_tagged_ngda' : datagovtheme_helpers .is_tagged_ngda ,
92
+ 'is_collection_parent' : datagovtheme_helpers .is_collection_parent ,
92
93
'render_datetime_datagov' : datagovtheme_helpers .render_datetime_datagov ,
93
94
'get_harvest_object_formats' : datagovtheme_helpers .get_harvest_object_formats ,
94
95
'get_bureau_info' : datagovtheme_helpers .get_bureau_info ,
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ <h3 class="dataset-heading" pkg_id="{{ package.id }}">
43
43
</ span >
44
44
{% endif %}
45
45
46
- {% if h.get_pkg_dict_extra (package, 'collection_metadata', '' ) %}
46
+ {% if h.is_collection_parent (package) %}
47
47
< span class ="dataset-collection label {{ 'label-default' }} ">
48
48
< i class ="icon-collection "> </ i >
49
49
{{ _('Collection') }}
Original file line number Diff line number Diff line change @@ -3,5 +3,4 @@ factory-boy>=2
3
3
flake8
4
4
mock
5
5
pytest
6
- pytest-ckan
7
6
pytest-cov
You can’t perform that action at this time.
0 commit comments