diff --git a/ckanext/odsh/helpers_tpsh.py b/ckanext/odsh/helpers_tpsh.py index 695d372ec5cd4b70f18cb4f2edc4534607ad0390..ce7a5c504393da47591f1b5efa16ded42d4ffd1c 100644 --- a/ckanext/odsh/helpers_tpsh.py +++ b/ckanext/odsh/helpers_tpsh.py @@ -1,9 +1,7 @@ # encoding: utf-8 import csv -import datetime import logging -from string import lower import json import re import urllib2 @@ -13,21 +11,21 @@ import os from ckan.common import config import ckan.lib.helpers as helpers -import ckan.logic.action.create as create import ckan.model as model import ckan.plugins.toolkit as toolkit - import ckanext.odsh.helpers as odsh_helpers + log = logging.getLogger(__name__) + CKAN_TYPES = {'http://dcat-ap.de/def/datasetTypes/collection': 'collection'} def map_dct_type_to_ckan_type(dct_type): ''' - matches the field dct:type from a harvested rdf file + matches the field dct:type from a harvested rdf file to the corresponding ckan package type ''' ckan_type = CKAN_TYPES.get(dct_type) @@ -142,6 +140,10 @@ def _get_language_id(pkg_dict): language_id_cleaned = re.sub('[\[\]\"]', '', language_id) return language_id_cleaned +def get_language_human_readable(language_id): + LANGUAGE_MAPPING = load_language_mapping() + return LANGUAGE_MAPPING.get(language_id) + def get_spatial_for_selection(): mapping_path = config.get('ckanext.odsh.spatial.mapping') try: @@ -152,10 +154,10 @@ def get_spatial_for_selection(): cr = csv.reader(mapping_file, delimiter="\t") spatial_mapping = list() for row in cr: - key = row[0].decode('UTF-8') + key = row[0].decode('UTF-8') value = row[1].decode('UTF-8') - spatial_mapping.append({'key':key, 'value':value}) - spatial_mapping.append({'key':'', 'value':''}) + spatial_mapping.append({'key': key, 'value': value}) + spatial_mapping.append({'key': '', 'value': ''}) return spatial_mapping def get_subject_for_selection(): @@ -179,7 +181,7 @@ def get_package_dict(name): return package_dict def size_of_fmt(num, suffix='B'): - for unit in ['',' k',' M',' G',' T',' P',' E',' Z']: + for unit in ['', ' k', ' M', ' G', ' T', ' P', ' E', ' Z']: if abs(num) < 1000.0: return "%3.1f%s%s" % (num, unit, suffix) num /= 1000.0 @@ -188,7 +190,7 @@ def size_of_fmt(num, suffix='B'): def get_resource_size(resource): resource_size = resource.get('size') if resource_size: - return size_of_fmt(resource_size) + return size_of_fmt(resource_size) def get_address_org(organization): diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 800184e223445fe3c9fd829441518a58fb5efbcc..f01877742c8722f3d2dd930bcf2f45b3bf2a148a 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -177,6 +177,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'groups': _('Kategorie'), 'subject_text': _('Informationsgegenstand'), 'tags': _('Tags'), + 'language': _('Language'), }) def group_facets(self, facets_dict, group_type, package_type): @@ -385,6 +386,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'tpsh_get_body_mail':helpers_tpsh.get_body_mail, 'tpsh_git_commit_hash': helpers_tpsh.git_commit_hash, 'tpsh_is_informationsgegenstand_gerichtsurteil_selected': helpers_tpsh.is_informationsgegenstand_gerichtsurteil_selected, + 'tpsh_get_language_human_readable': helpers_tpsh.get_language_human_readable, } diff --git a/ckanext/odsh/templates/snippets/facet_list.html b/ckanext/odsh/templates/snippets/facet_list.html index d2b8521998aa412d9b20b7e92d7443c2bfa84bff..ee1bbcbd7a587c0043bfbd178645da749da4b798 100644 --- a/ckanext/odsh/templates/snippets/facet_list.html +++ b/ckanext/odsh/templates/snippets/facet_list.html @@ -44,9 +44,15 @@ {% endif %} <label class="odsh-visible-label" for="check-{{ title.lower() }}-{{ loop.index }}"> + {% if name=='language' %} + <a href="{{ href }}" title="{{ label if label != label_truncated else '' }}"> + <span id="description-{{ title.lower() }}-{{ loop.index }}">{{ h.tpsh_get_language_human_readable(label) }}</span> + </a> + {% else %} <a href="{{ href }}" title="{{ label if label != label_truncated else '' }}"> <span id="description-{{ title.lower() }}-{{ loop.index }}">{{ label }}</span> </a> + {% endif %} </label> </div> <div class="facet_count"> diff --git a/ckanext/odsh/templates/snippets/search_form.html b/ckanext/odsh/templates/snippets/search_form.html index d14cbccc8cda4573b4e39675957478a7a2e4149f..ebdcbf4f42164eb50b2153db3be5f1ebf7410608 100644 --- a/ckanext/odsh/templates/snippets/search_form.html +++ b/ckanext/odsh/templates/snippets/search_form.html @@ -77,8 +77,10 @@ {% set search_facets_items = facets.search.get(field)['items'] %} {% for value in facets.fields[field] %} <span class="filtered pill"> - {% if(field=='openness')%} + {% if field == 'openness' %} {{_(value)}} + {%- elif field == 'language' -%} + {{ h.tpsh_get_language_human_readable(value) }} {%- else -%} {%- if facets.translated_fields and facets.translated_fields.has_key((field,value)) -%} {{ facets.translated_fields[(field,value)] }}