Skip to content

Commit

Permalink
Merge pull request #3 from JiscSD/update_year_filter_ordering
Browse files Browse the repository at this point in the history
Update year filter ordering
  • Loading branch information
paulchauch authored Jan 11, 2023
2 parents 00e49bb + 247c74a commit 479ae06
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ coverage.xml

# Sphinx documentation
docs/_build/
*.log
9 changes: 8 additions & 1 deletion ckanext/customised_fields_from_tag_vocabulary/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ckan.plugins.toolkit import Invalid

log = logging.getLogger(__name__)
facet_order_by_display_name = ['Year']

def get_vocab_tag_list(vocab):
try:
Expand All @@ -24,6 +25,12 @@ def get_vocab_tag_list(vocab):
except toolkit.ObjectNotFound:
return None

def reorder_facet(title, facet):
if title in facet_order_by_display_name:
sfacet = sorted(facet, key=lambda d: d['display_name'], reverse=True)
return sfacet
return facet

class CustomisedFieldsFromTagVocabularyPlugin(plugins.SingletonPlugin, toolkit.DefaultDatasetForm):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.ITemplateHelpers)
Expand Down Expand Up @@ -107,7 +114,7 @@ def update_config(self, _config):
# ITemplateHelpers

def get_helpers(self):
return {'get_vocab_tag_list': get_vocab_tag_list}
return {'get_vocab_tag_list': get_vocab_tag_list, 'reorder_facet': reorder_facet}

def is_fallback(self):
# Return True to register this plugin as the default handler for
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% ckan_extends %}

{% block facet_list_items %}
{% with items = items or h.get_facet_items_dict(name, search_facets or c.search_facets) %}
{% if items %}
{% set sorted_items = h.reorder_facet(title, items) %}
<nav aria-label="{{ title }}">
<ul class="{{ nav_class or 'list-unstyled nav nav-simple nav-facet' }}">
{% for item in sorted_items %}
{% set href = h.remove_url_param(name, item.name, extras=extras, alternative_url=alternative_url) if item.active else h.add_url_param(new_params={name: item.name}, extras=extras, alternative_url=alternative_url) %}
{% set label = label_function(item) if label_function else item.display_name %}
{% set label_truncated = h.truncate(label, 22) if not label_function else label %}
{% set count = count_label(item['count']) if count_label else ('%d' % item['count']) %}
<li class="{{ nav_item_class or 'nav-item' }}{% if item.active %} active{% endif %}">
<a href="{{ href }}" title="{{ label if label != label_truncated else '' }}">
<span class="item-label">{{ label_truncated }}</span>
<span class="hidden separator"> - </span>
<span class="item-count badge">{{ count }}</span>
</a>
</li>
{% endfor %}
</ul>
</nav>

<p class="module-footer">
{% if h.get_param_int('_%s_limit' % name) %}
{% if h.has_more_facets(name, search_facets or c.search_facets) %}
<a href="{{ h.remove_url_param('_%s_limit' % name, replace=0, extras=extras, alternative_url=alternative_url) }}" class="read-more">{{ _('Show More {facet_type}').format(facet_type=title) }}</a>
{% endif %}
{% else %}
<a href="{{ h.remove_url_param('_%s_limit' % name, extras=extras, alternative_url=alternative_url) }}" class="read-more">{{ _('Show Only Popular {facet_type}').format(facet_type=title) }}</a>
{% endif %}
</p>
{% else %}
<p class="module-content empty">{{ _('There are no {facet_type} that match this search').format(facet_type=title) }}</p>
{% endif %}
{% endwith %}
{% endblock %}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# http://packaging.python.org/en/latest/tutorial.html#version
version='0.0.3',
version='0.0.4',

description='''CKAN plugin for the UKDS CKAN platform''',
long_description=long_description,
Expand Down

0 comments on commit 479ae06

Please sign in to comment.