Skip to content

Commit

Permalink
Added the 'get_site_statistics' helper function which was removed in …
Browse files Browse the repository at this point in the history
…CKAN 2.11 while it was a core helper function before.
  • Loading branch information
ntwalibas committed Nov 12, 2024
1 parent 21c660d commit d4f5558
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion ckanext/dms/helpers.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion ckanext/dms/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4f5558

Please sign in to comment.