From d4f5558531cb5e5defb47a308772807a7a69acce Mon Sep 17 00:00:00 2001 From: Ntwali B Date: Tue, 12 Nov 2024 09:54:46 +0100 Subject: [PATCH] Added the 'get_site_statistics' helper function which was removed in CKAN 2.11 while it was a core helper function before. --- ckanext/dms/helpers.py | 14 +++++++++++++- ckanext/dms/plugin.py | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ckanext/dms/helpers.py b/ckanext/dms/helpers.py index bd18d1a..be771ab 100644 --- a/ckanext/dms/helpers.py +++ b/ckanext/dms/helpers.py @@ -1,5 +1,5 @@ -import ckan.logic as logic import ckan.model as model +import ckan.logic as logic from ckan.common import c, request, is_flask_request # for datetime string conversion @@ -84,3 +84,15 @@ def get_all_groups(): return logic.get_action('group_list')( data_dict={'sort': 'title asc', 'all_fields': True}) + +def get_site_statistics() -> dict[str, int]: + '''This function used be a core helper but it was removed in CKAN 2.11.0 + We reproduce it here to templates can continue working as usual. + ''' + stats = {} + stats['dataset_count'] = logic.get_action('package_search')( + {}, {"rows": 1})['count'] + stats['group_count'] = len(logic.get_action('group_list')({}, {})) + stats['organization_count'] = len( + logic.get_action('organization_list')({}, {})) + return stats diff --git a/ckanext/dms/plugin.py b/ckanext/dms/plugin.py index 99ce57f..489aaa7 100644 --- a/ckanext/dms/plugin.py +++ b/ckanext/dms/plugin.py @@ -33,7 +33,8 @@ def get_helpers(self): 'get_facet_items_dict': get_facet_items_dict, 'get_featured_datasets': ckanext.dms.helpers.get_featured_datasets, 'get_user_from_id': ckanext.dms.helpers.get_user_from_id, - 'get_all_groups': ckanext.dms.helpers.get_all_groups + 'get_all_groups': ckanext.dms.helpers.get_all_groups, + 'get_site_statistics': ckanext.dms.helpers.get_site_statistics, } # IConfigurer