From ed36a128958fd6446ef08e81ed703f87acf30dd3 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Wed, 25 Feb 2015 15:47:06 +0000 Subject: [PATCH] [#277] Add notices explaining that only the default codelists are used --- data.py | 10 ++++++++-- make_html.py | 1 + templates/codelist.html | 3 +++ templates/publisher.html | 15 ++++++++++++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/data.py b/data.py index ac2afa666f..59c86c592e 100644 --- a/data.py +++ b/data.py @@ -86,17 +86,23 @@ def get_publisher_stats(publisher, stats_type='aggregated'): for issue in reader: data_tickets[issue['data_provider_regisrty_id']].append(issue) -def create_codelist_mapping(major_version): - codelist_mapping = {x['path']:x['codelist'] for x in json.load(open('data/IATI-Codelists-{}/out/clv2/mapping.json'.format(major_version)))} +def transform_codelist_mapping_keys(codelist_mapping): # Perform the same transformation as https://github.com/IATI/IATI-Stats/blob/d622f8e88af4d33b1161f906ec1b53c63f2f0936/stats.py#L12 codelist_mapping = {k:v for k,v in codelist_mapping.items() if not k.startswith('//iati-organisation') } codelist_mapping = {re.sub('^\/\/iati-activity', './', k):v for k,v in codelist_mapping.items() } codelist_mapping = {re.sub('^\/\/', './/', k):v for k,v, in codelist_mapping.items() } return codelist_mapping +def create_codelist_mapping(major_version): + codelist_mapping = {x['path']:x['codelist'] for x in json.load(open('data/IATI-Codelists-{}/out/clv2/mapping.json'.format(major_version)))} + return transform_codelist_mapping_keys(codelist_mapping) + MAJOR_VERSIONS = ['1', '2'] codelist_mapping = { v:create_codelist_mapping(v) for v in MAJOR_VERSIONS } +codelist_conditions = { + major_version: transform_codelist_mapping_keys({ x['path']:x.get('condition') for x in json.load(open('data/IATI-Codelists-{}/out/clv2/mapping.json'.format(major_version)))}) + for major_version in MAJOR_VERSIONS } codelist_sets = { major_version: { diff --git a/make_html.py b/make_html.py index bc3d9d3f86..70ccdd33bd 100644 --- a/make_html.py +++ b/make_html.py @@ -95,6 +95,7 @@ def registration_agency(orgid): app.jinja_env.globals['slugs'] = slugs app.jinja_env.globals['codelist_mapping'] = codelist_mapping +app.jinja_env.globals['codelist_conditions'] = codelist_conditions app.jinja_env.globals['codelist_sets'] = codelist_sets basic_page_names = [ diff --git a/templates/codelist.html b/templates/codelist.html index 433f46d0fb..6f1979e23f 100644 --- a/templates/codelist.html +++ b/templates/codelist.html @@ -8,6 +8,9 @@

Codelist values used for {{element}}

Who uses {{codelist_mapping[major_version].get(element)}} in {{element}}?

(for files published to version {{major_version}}.xx of the standard)

+{% if codelist_conditions[major_version][element] %} +
Note: this attribute can be on multiple codelists (specified by the @vocabulary attribute) but the dashboard only currently checks against the default codelist - see issue #174. Therefore some publishers may incorrectly show up as "Not On Codelist".
+{% endif %}

(This page in JSON format)

Values should be on the {{codelist_mapping[major_version].get(element)}} codelist.

{% endblock %} diff --git a/templates/publisher.html b/templates/publisher.html index 7b12b1ecec..b7316122eb 100644 --- a/templates/publisher.html +++ b/templates/publisher.html @@ -365,9 +365,18 @@

Codelist Values (version {{major_version}}.xx)

{% endwith %} {% with codes=sorted(set(values.keys()).difference(codelist_sets[major_version].get(codelist_mapping[major_version].get(element)))) %} - {% if codes|count %} - {{codes|count}} - {%else%}{{codes|count}}{%endif%} + + {% if codes|count %} + + {{codes|count}} + + {% if codelist_conditions[major_version][element] %} +
Note: this attribute can be on multiple codelists (specified by the @vocabulary attribute) but the Dashboard only currently checks against the default codelist - see issue #174. Therefore some publishers may incorrectly show up as "Not On Codelist".
+ {% endif %} + {%else%} + {{codes|count}} + {%endif%} + {% endwith %} {% endwith %}