diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index aeb8d66d35e..840393fc2d8 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -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 ''' @@ -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', diff --git a/ckan/lib/search/index.py b/ckan/lib/search/index.py index d77d7cbfa12..9b50031df4b 100644 --- a/ckan/lib/search/index.py +++ b/ckan/lib/search/index.py @@ -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: diff --git a/ckan/templates/package/search.html b/ckan/templates/package/search.html index 73326b159d5..1271aebab17 100644 --- a/ckan/templates/package/search.html +++ b/ckan/templates/package/search.html @@ -38,6 +38,7 @@