diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index 138f96b5b8a2f9b82f5326afb550c05551468320..12e9aebbc00f08b1e03824e2e0f1c197230ff6bb 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -12,6 +12,7 @@ from ckan.common import config import urllib import hashlib import re +from ckan.common import request get_action = logic.get_action log = logging.getLogger(__name__) @@ -193,4 +194,20 @@ def presorted_license_options(existing_license_id=None): return [('','')]+[ (license_id, register[license_id].title if license_id in register else license_id) - for license_id in license_ids] \ No newline at end of file + for license_id in license_ids] + + +def odsh_has_more_facets(facet, limit=None, exclude_active=False): + facets = [] + for facet_item in c.search_facets.get(facet)['items']: + if not len(facet_item['name'].strip()) or facet_item['count']==0: + continue + if not (facet, facet_item['name']) in request.params.items(): + facets.append(dict(active=False, **facet_item)) + elif not exclude_active: + facets.append(dict(active=True, **facet_item)) + if c.search_facets_limits and limit is None: + limit = c.search_facets_limits.get(facet) + if limit is not None and len(facets) > limit: + return True + return False diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 335544fa48babdfb29595c842e3928737e4c7628..430fd4e560c3051d053a4bda8e1a44a0aca1f027 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -248,7 +248,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'odsh_create_checksum': odsh_helpers.odsh_create_checksum, 'presorted_license_options': odsh_helpers.presorted_license_options, 'odsh_tracking_id': odsh_helpers.odsh_tracking_id, - 'odsh_tracking_url': odsh_helpers.odsh_tracking_url + 'odsh_tracking_url': odsh_helpers.odsh_tracking_url, + 'odsh_has_more_facets': odsh_helpers.odsh_has_more_facets } def after_map(self, map): diff --git a/ckanext/odsh/templates/snippets/facet_list.html b/ckanext/odsh/templates/snippets/facet_list.html index 38a8e1a4bcac50baf0dafdcc61bcafe8c9aebb28..1742e4447e613f1458b4a0789fef566e706a29d2 100644 --- a/ckanext/odsh/templates/snippets/facet_list.html +++ b/ckanext/odsh/templates/snippets/facet_list.html @@ -42,7 +42,7 @@ <div class="module-footer"> {% if h.get_param_int('_%s_limit' % name) %} - {% if h.has_more_facets(name) %} + {% if h.odsh_has_more_facets(name) %} <a href="{{ h.remove_url_param('_%s_limit' % name, replace=0, extras=extras, alternative_url=alternative_url) }}" class="read-more">> {{ _('Show More') }}</a> {% endif %}