Skip to content

Commit

Permalink
[#666] Fix group/org facet titles
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes authored and amercader committed Mar 27, 2013
1 parent 4b03385 commit 5adb70f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
21 changes: 21 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -1450,6 +1450,26 @@ def resource_preview(resource, pkg_id):
resource_url=url,
raw_resource_url=resource.get('url'))

def list_dict_filter(list_, search_field, output_field, value):
''' Takes a list of dicts and returns the value of a given key if the
item has a matching value for a supplied key
:param list_: the list to search through for matching items
:type list_: list of dicts
:param search_field: the key to use to find matching items
:type search_field: string
:param output_field: the key to use to output the value
:type output_field: string
:param value: the value to search for
'''

for item in list_:
if item.get(search_field) == value:
return item.get(output_field, value)
return value

def SI_number_span(number):
''' outputs a span with the number in SI unit eg 14700 -> 14.7k '''
Expand Down Expand Up @@ -1548,6 +1568,7 @@ def SI_number_span(number):
'localised_SI_number',
'localised_nice_date',
'localised_filesize',
'list_dict_filter',
# imported into ckan.lib.helpers
'literal',
'link_to',
Expand Down
3 changes: 1 addition & 2 deletions ckan/lib/search/index.py
Expand Up @@ -157,12 +157,11 @@ def index_package(self, pkg_dict, defer_commit=False):

# if there is an owner_org we want to add this to groups for index
# purposes
if pkg_dict['owner_org'] and pkg_dict.get('organization'):
if pkg_dict.get('organization'):
pkg_dict['organization'] = pkg_dict['organization']['name']
else:
pkg_dict['organization'] = None


# tracking
tracking_summary = pkg_dict.pop('tracking_summary', None)
if tracking_summary:
Expand Down
2 changes: 2 additions & 0 deletions ckan/templates/package/search.html
Expand Up @@ -38,13 +38,15 @@
</strong>
<div class="filter-list">
{% for field in c.fields_grouped %}
{% set search_facets_items = c.search_facets.get(field)['items'] %}
<span class="facet">{{ c.facet_titles.get(field) }}:</span>
{% for value in c.fields_grouped[field] %}
<span class="filtered pill">
{%- if c.translated_fields and c.translated_fields.has_key((field,value)) -%}
{{ c.translated_fields[(field,value)] }}
{%- else -%}
{{ value }}
{{ h.list_dict_filter(search_facets_items , 'name', 'display_name', value) }}
{%- endif %}
<a href="{{ c.remove_field(field, value) }}" class="remove" title="{{ _('Remove') }}"><i class="icon-remove"></i></a>
</span>
Expand Down

0 comments on commit 5adb70f

Please sign in to comment.