Skip to content

Commit 411a68e

Browse files
committed
cove: Add closed codelist validation
1 parent d1711ea commit 411a68e

File tree

8 files changed

+53
-17
lines changed

8 files changed

+53
-17
lines changed

cove/cove_360/templates/cove_360/explore.html

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ <h3 class="panel-title panel-title-explore" id="conversion-title">
275275
<div class="panel panel-default">
276276
<div class="panel-heading" data-toggle="collapse" data-target="#validation-body">
277277
<h3 class="panel-title panel-title-explore">
278-
{% if validation_errors %}
278+
{% if validation_errors or additional_closed_codelist_values %}
279279
<span class="font-tick cross" aria-hidden="true"></span>
280-
{% trans "This data does not use the 360Giving Data Standard correctly" %} <small>{% blocktrans count n_errors=validation_errors_count %} {{n_errors}} Error.{% plural %}{{n_errors}} Errors {% endblocktrans %}</small>
280+
{% trans "This data does not use the 360Giving Data Standard correctly" %} <small>{% blocktrans count n_errors=validation_and_closed_codelist_errors_count %} {{n_errors}} Error.{% plural %}{{n_errors}} Errors {% endblocktrans %}</small>
281281
{% else %}
282282
<span class="font-tick tick" aria-hidden="true"></span>
283283
{% trans "This data uses the 360Giving Data Standard correctly" %}
@@ -288,15 +288,15 @@ <h3 class="panel-title panel-title-explore">
288288
<div id="validation-body" class="collapse">
289289
<div class="panel-body">
290290
<p class="explanation">
291-
{% if validation_errors %}
291+
{% if validation_errors or additional_closed_codelist_values %}
292292
{% trans "Sorry your data is not yet using the 360Giving Data Standard. We used the " %}
293293
{% else %}
294294
{% trans "Congratulations! Your data is using the 360Giving Data Standard. We used the " %}
295295
{% endif %}
296296
<a href="https://www.threesixtygiving.org/standard/reference/#toc-360giving-json-schemas"> 360Giving JSON Package Schema</a> {% trans "to check this." %}
297297
</p>
298298
<div class="explore-help">{% trans "This means that the data" %}
299-
{% if validation_errors %}
299+
{% if validation_errors or additional_closed_codelist_values %}
300300
{% trans " does not meet " %}
301301
{% else %}
302302
{% trans " meets " %}
@@ -305,7 +305,7 @@ <h3 class="panel-title panel-title-explore">
305305
{% blocktrans %}the requirements of the <a href="https://standard.threesixtygiving.org/en/latest/technical/reference/">360Giving Data Standard</a>.{% endblocktrans %}
306306
{% blocktrans %} Making sure your data uses the standard correctly is important. Otherwise it cannot be used alongside other valid 360Giving data and cannot be included in 360Giving tools, such as GrantNav and 360Insights.{% endblocktrans %}
307307
</diV>
308-
{% if validation_errors %}
308+
{% if validation_errors or additional_closed_codelist_values %}
309309
<br>
310310
<p class="explanation">&nbsp;{% trans "The following <strong>errors</strong> are preventing your data from being valid 360Giving data. Please use the feedback below to find and resolve the issues in your file" %}</p>
311311
<br>
@@ -345,6 +345,24 @@ <h4>Incorrect Formats</h4>
345345
{% endfor %}
346346
{% endif %}
347347
{% endwith %}
348+
{% if additional_closed_codelist_values %}
349+
<div class="panel panel-default">
350+
<div class="panel-heading">
351+
<h4>{% trans 'Codelist Errors' %}</h4>
352+
</div>
353+
<div>
354+
<div class="panel-body">
355+
<p>Some or all of your entries do not use the 360Giving Data Standard codelists correctly.</p>
356+
<p>{% blocktrans %}The fields below use closed codelists. When using these fields, you <strong>must</strong> use one of the pre-defined codelist values. If you use a value that is not on the relevant codelist, your data will not pass structural checks.{% endblocktrans %}</p>
357+
</div>
358+
</p>
359+
{% with additional_codelist_values=additional_closed_codelist_values %}
360+
<div>{% include "additional_codelist_values.html" %}</div>
361+
{% endwith %}
362+
</div>
363+
</div>
364+
{% endif %}
365+
{% endif %}
348366
{% with validation_errors=validation_errors_grouped.other error_prefix='other-' %}
349367
{% if validation_errors %}
350368
<div class="panel panel-default">
@@ -363,12 +381,12 @@ <h4>Other</h4>
363381
{% endfor %}
364382
{% endif %}
365383
{% endwith %}
366-
{% endif %}
367384
</div>
368385
</div>
369386
</div>
370387
{% endblock validation %}
371388

389+
372390
{% block quality_accuracy %}
373391
{% if quality_accuracy_checks_count %}
374392
<div class="panel panel-default">

lib360dataquality/cove/schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ class Schema360(SchemaJsonMixin):
1010
pkg_schema_name = config['schema_name']
1111
schema_url = urljoin(schema_host, schema_name)
1212
pkg_schema_url = urljoin(schema_host, pkg_schema_name)
13+
codelists = config['codelists_host']

lib360dataquality/cove/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'schema_name': '360-giving-package-schema.json',
1212
'schema_item_name': '360-giving-schema.json',
1313
'schema_host': f'https://raw.githubusercontent.com/ThreeSixtyGiving/standard/{os.environ.get("SCHEMA_BRANCH", "master")}/schema/',
14+
'codelists_host': f'https://raw.githubusercontent.com/ThreeSixtyGiving/standard/{os.environ.get("SCHEMA_BRANCH", "master")}/codelists/',
1415
'schema_version': None,
1516
'schema_version_choices': None,
1617
'root_list_path': 'grants',

lib360dataquality/cove/threesixtygiving.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import openpyxl
1111
import pytz
1212
from dateutil.relativedelta import relativedelta
13-
from libcove.lib.common import common_checks_context, get_orgids_prefixes
13+
from libcove.lib.common import common_checks_context, get_additional_codelist_values, get_orgids_prefixes
1414
from rangedict import RangeDict as range_dict
1515

1616
try:
@@ -350,6 +350,22 @@ def common_checks_360(
350350
}
351351
)
352352

353+
additional_codelist_values = get_additional_codelist_values(schema_obj, json_data)
354+
closed_codelist_values = {
355+
key: value for key, value in additional_codelist_values.items() if not value["isopen"]
356+
}
357+
open_codelist_values = {key: value for key, value in additional_codelist_values.items() if value["isopen"]}
358+
359+
closed_codelist_errors_count = sum(len(value['values']) for value in closed_codelist_values.values())
360+
361+
context.update(
362+
{
363+
"additional_closed_codelist_values": closed_codelist_values,
364+
"additional_open_codelist_values": open_codelist_values,
365+
"validation_and_closed_codelist_errors_count": context["validation_errors_count"] + closed_codelist_errors_count
366+
}
367+
)
368+
353369
return context
354370

355371

requirements_cove.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Django>3.2,<3.3
33
#^^ rq.filter: <1.12
44
flattentool>=0.17.0
5-
libcove
5+
libcove>=0.29.0
66
libcoveweb
77
django-bootstrap3
88
django-debug-toolbar

requirements_cove.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
2-
# This file is autogenerated by pip-compile with python 3.8
3-
# To update, run:
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
44
#
55
# pip-compile requirements_cove.in
66
#
@@ -75,7 +75,7 @@ jsonschema==3.2.0
7575
# via
7676
# -r requirements_cove.in
7777
# libcove
78-
libcove==0.27.0
78+
libcove==0.29.0
7979
# via
8080
# -r requirements_cove.in
8181
# lib360dataquality

requirements_cove_dev.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
2-
# This file is autogenerated by pip-compile with python 3.8
3-
# To update, run:
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
44
#
55
# pip-compile requirements_cove_dev.in
66
#
@@ -144,7 +144,7 @@ jsonschema==3.2.0
144144
# via
145145
# -r requirements_cove.in
146146
# libcove
147-
libcove==0.27.0
147+
libcove==0.29.0
148148
# via
149149
# -r requirements_cove.in
150150
# lib360dataquality

requirements_cove_dokku.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
2-
# This file is autogenerated by pip-compile with python 3.8
3-
# To update, run:
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
44
#
55
# pip-compile requirements_cove_dokku.in
66
#
@@ -100,7 +100,7 @@ jsonschema==3.2.0
100100
# via
101101
# -r requirements_cove.txt
102102
# libcove
103-
libcove==0.27.0
103+
libcove==0.29.0
104104
# via
105105
# -r requirements_cove.txt
106106
# lib360dataquality

0 commit comments

Comments
 (0)