Skip to content

Commit

Permalink
[#277] Add notices explaining that only the default codelists are used
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Feb 25, 2015
1 parent 485982e commit ed36a12
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
10 changes: 8 additions & 2 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions make_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
3 changes: 3 additions & 0 deletions templates/codelist.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<h1>Codelist values used for <code>{{element}}</code></h1>
<p class="lead">Who uses <code>{{codelist_mapping[major_version].get(element)}}</code> in <code><a href="{{element|xpath_to_url}}">{{element}}</a></code>?</p>
<p class="lead">(for files published to version {{major_version}}.xx of the standard)</p>
{% if codelist_conditions[major_version][element] %}
<div class="alert alert-warning">Note: this attribute can be on multiple codelists (specified by the @vocabulary attribute) but the dashboard only currently checks against the default codelist - see <a href="https://github.com/IATI/IATI-Dashboard/issues/174">issue #174</a>. Therefore some publishers may incorrectly show up as "Not On Codelist".</div>
{% endif %}
<p style="float:right">(<a href="{{stats_url}}/current/inverted-publisher/codelist_values.json">This page in JSON format</a>)</p>
<p>Values should be on the <code><a href="http://iatistandard.org/{% if major_version=='1' %}105/{%endif%}codelists/{{codelist_mapping[major_version].get(element)}}/">{{codelist_mapping[major_version].get(element)}}</a></code> codelist.</p>
{% endblock %}
Expand Down
15 changes: 12 additions & 3 deletions templates/publisher.html
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,18 @@ <h3 class="panel-title">Codelist Values (version {{major_version}}.xx)</h3>
</td>
{% endwith %}
{% with codes=sorted(set(values.keys()).difference(codelist_sets[major_version].get(codelist_mapping[major_version].get(element)))) %}
<td>{% if codes|count %}
<a href="javascript: return false;" class="popover-html" title="Values not on codelist for {{element}}" data-content="{% for code in codes %}<code>{{code}}</code> {% endfor %}">{{codes|count}}</a></td>
{%else%}{{codes|count}}{%endif%}
<td>
{% if codes|count %}
<a href="javascript: return false;" class="popover-html" title="Values not on codelist for {{element}}" data-content="{% for code in codes %}<code>{{code}}</code> {% endfor %}">
{{codes|count}}
</a>
{% if codelist_conditions[major_version][element] %}
<div class="alert alert-warning">Note: this attribute can be on multiple codelists (specified by the @vocabulary attribute) but the Dashboard only currently checks against the default codelist - see <a href="https://github.com/IATI/IATI-Dashboard/issues/174">issue #174</a>. Therefore some publishers may incorrectly show up as "Not On Codelist".</div>
{% endif %}
{%else%}
{{codes|count}}
{%endif%}
</td>
{% endwith %}
{% endwith %}
</tr>
Expand Down

0 comments on commit ed36a12

Please sign in to comment.