From 41a586bf7aca29dbc9a32e798024c19d64a0a84f Mon Sep 17 00:00:00 2001 From: Ian Ward Date: Thu, 12 Jan 2017 12:20:46 -0500 Subject: [PATCH] [#3385] organization_list_for_user: include_dataset_count parameter --- ckan/lib/helpers.py | 7 +++++-- ckan/logic/action/get.py | 5 ++++- ckan/templates/user/dashboard_organizations.html | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index f077f2cc9e6..524e1f3a6c8 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -1664,12 +1664,15 @@ def groups_available(am_member=False): @core_helper -def organizations_available(permission='manage_group'): +def organizations_available( + permission='manage_group', include_dataset_count=False): '''Return a list of organizations that the current user has the specified permission for. ''' context = {'user': c.user} - data_dict = {'permission': permission} + data_dict = { + 'permission': permission, + 'include_dataset_count': include_dataset_count} return logic.get_action('organization_list_for_user')(context, data_dict) diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index 193da64f492..04fa8dfeb4f 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -628,6 +628,9 @@ def organization_list_for_user(context, data_dict): returned organizations, for example ``"read"`` or ``"create_dataset"`` (optional, default: ``"manage_group"``) :type permission: string + :param include_dataset_count: include the package_count in each org + (optional, default: ``False``) + :type include_dataset_count: boolean :returns: list of organizations that the user has the given permission for :rtype: list of dicts @@ -697,7 +700,7 @@ def organization_list_for_user(context, data_dict): context['with_capacity'] = True orgs_list = model_dictize.group_list_dictize(orgs_and_capacities, context, - with_package_counts=False) + with_package_counts=asbool(data_dict.get('include_dataset_count'))) return orgs_list diff --git a/ckan/templates/user/dashboard_organizations.html b/ckan/templates/user/dashboard_organizations.html index cff5801bb28..6ad221d6ea1 100644 --- a/ckan/templates/user/dashboard_organizations.html +++ b/ckan/templates/user/dashboard_organizations.html @@ -10,7 +10,8 @@ {% block primary_content_inner %}

{{ _('My Organizations') }}

- {% set organizations = h.organizations_available(permission='manage_group') %} + {% set organizations = h.organizations_available(permission='manage_group', + include_dataset_count=True) %} {% if organizations %}
{% snippet "organization/snippets/organization_list.html", organizations=organizations, show_capacity=True %}