Skip to content
Snippets Groups Projects
Commit 8529df1f authored by anonymous's avatar anonymous
Browse files

ODPSH-8: adds qa-functionality to our templates

parent 44df0724
No related branches found
No related tags found
No related merge requests found
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
......@@ -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():
......
{#
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>
......@@ -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">
......
......@@ -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,8 +20,8 @@
"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",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment