diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py new file mode 100644 index 0000000000000000000000000000000000000000..6a9786bb88ac892d300050117ff6d7f27ef331af --- /dev/null +++ b/ckanext/odsh/helpers.py @@ -0,0 +1,20 @@ +import logging +import traceback +import ast + +log = logging.getLogger(__name__) + + +def odsh_openness_score_dataset_html(dataset): + score = 0 + #dataset = json.loads(dataset) + for resource in dataset.get('resources'): + try: + qa = ast.literal_eval(resource.get('qa')) + resource_score = qa.get('openness_score') + if resource_score > score: + score = resource_score + except AttributeError, e: + log.error('Error while calculating openness score %s: %s\nException: %s', + e.__class__.__name__, unicode(e), traceback.format_exc()) + return score diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 8a441626caed4bbffcb39b8021085d1e75b6f683..2e98cb6ceda0f0612e2e6764f48249ff4bedeae3 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -5,6 +5,7 @@ from ckan.lib.plugins import DefaultTranslation from ckan.lib.plugins import DefaultDatasetForm from ckan.common import OrderedDict import ckan.lib.helpers as helpers +import helpers as odsh_helpers import logging @@ -83,6 +84,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm 'odsh_now': odsh_now, 'odsh_group_id_selected': odsh_group_id_selected, 'odsh_get_facet_items_dict': odsh_get_facet_items_dict, + 'odsh_openness_score_dataset_html': odsh_helpers.odsh_openness_score_dataset_html, } def before_map(self, map): @@ -104,7 +106,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm return ['title','notes'] def _extraFields(self): - return ['publish_date','access_constraints','temporal_start','temporal_end','spatial_extension'] + return ['publish_date','access_constraints','temporal_start','temporal_end','spatial_extension', 'qa'] def _update_schema(self,schema): for field in self._extraFields(): diff --git a/ckanext/odsh/templates/qa/stars.html b/ckanext/odsh/templates/qa/stars.html new file mode 100644 index 0000000000000000000000000000000000000000..48373d1f22ba0ed21086d6a8d4dc666d166e1458 --- /dev/null +++ b/ckanext/odsh/templates/qa/stars.html @@ -0,0 +1,28 @@ +{# +Renders a set of stars for the current dataset or if it has none a string +explaining the reason. + +stars - The number of stars assigned to the dataset. +reason - A reason why the dataset doesn't have a rating. + +{% snippet "qa/stars.html", stars=4 %} + +#} +<span class="star-rating{% if stars == 0 %} no-stars{% endif %}"> + {%- if stars == None -%} + {{ reason }} + {%- else -%} + <span class="star-rating-stars"> + {%- for index in range(stars) -%} + <span class="fa fa-star odsh-star"></span> + {%- endfor -%} + {%- for index in range(5-stars) -%} + <span class="fa fa-star-o odsh-star"></span> + {%- endfor -%} + {%- if stars == 0 -%} + {# 0 stars looks awfully like 5 stars, so be explicit #} + {# {{ _("{0} out of {1}").format(stars, 5) }} #} + {%- endif -%} + </span> + {%- endif -%} +</span> diff --git a/ckanext/odsh/templates/snippets/package_item.html b/ckanext/odsh/templates/snippets/package_item.html index 7eb2551dfeef9a0dfc8b9be4a53b43479a31ced5..9ce161b5313f46e20f4bec033277c3d725159e3a 100644 --- a/ckanext/odsh/templates/snippets/package_item.html +++ b/ckanext/odsh/templates/snippets/package_item.html @@ -20,6 +20,7 @@ Example: {% set license = package.license or '-' %} {% set timerange = '-' %} {% set org = package.organization.title or package.organization.name or '-' %} +{% set stars = h.odsh_openness_score_dataset_html(package) %} {% set access_count=(package.tracking_summary.total if package.tracking_summary) or '-' %} {% set timerange_label ='Zeitraum' %} {% set access_count_label ='Aufrufe' %} @@ -81,7 +82,7 @@ Example: {% endblock %} </ul> <div class="dataset-stars"> - <i class="fa fa-star odsh-star"></i><i class="fa fa-star odsh-star"></i><i class="fa fa-star odsh-star"></i><i class="fa fa-star odsh-star"></i><i class="fa fa-star-o odsh-star"></i> + {% snippet "qa/stars.html", stars=stars %} </div> <div class="dataset-info"> diff --git a/licenses.json b/licenses.json index 54e1227c3646920673c5b17c04096e7a3e7e3b27..a64f6d467611dec6994ed4ba852ae7879e24b87e 100644 --- a/licenses.json +++ b/licenses.json @@ -6,8 +6,8 @@ "family": "", "id": "http://dcat-ap.de/def/licenses/dl-by-de/2.0", "is_generic": true, - "is_okd_compliant": true, - "is_osi_compliant": false, + "od_conformance": "approved", + "osd_conformance": "not reviewed", "maintainer": "", "status": "active", "title": "Datenlizenz Deutschland Namensnennung 2.0", @@ -20,11 +20,11 @@ "family": "", "id": "http://dcat-ap.de/def/licenses/dl-zero-de/2.0", "is_generic": true, - "is_okd_compliant": true, - "is_osi_compliant": true, + "od_conformance": "approved", + "osd_conformance": "approved", "maintainer": "", "status": "active", "title": "Datenlizenz Deutschland – Zero – Version 2.0", "url": "https://www.govdata.de/dl-de/zero-2-0" } -] \ No newline at end of file +]