Skip to content

Commit

Permalink
Merge pull request #71 from frictionlessdata/use-frictionless-report-…
Browse files Browse the repository at this point in the history
…component

Uses new frictionless report component to display validation report
  • Loading branch information
amercader authored Oct 27, 2022
2 parents e774828 + c3b6807 commit fff8dc5
Show file tree
Hide file tree
Showing 23 changed files with 10,041 additions and 6,795 deletions.
2 changes: 2 additions & 0 deletions ckanext/validation/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def validation_extract_report_from_errors(errors):

return report, errors

def validation_dict(validation_json):
return json.loads(validation_json)

def dump_json_value(value, indent=None):
"""
Expand Down
12 changes: 6 additions & 6 deletions ckanext/validation/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,31 @@ def run_validation_job(resource):
schema = json.loads(schema)

_format = resource['format'].lower()

report = _validate_table(source, _format=_format, schema=schema, **options)

# Hide uploaded files
if type(report) == Report:
report = report.to_dict()

if 'tasks' in report:
for table in report['tasks']:
if table['place'].startswith('/'):
table['place'] = resource['url']
if 'warnings' in report:
validation.status = 'error'
for index, warning in enumerate(report['warnings']):
report['warnings'][index] = re.sub(r'Table ".*"', 'Table', warning)
if 'valid' in report:
validation.status = 'success' if report['valid'] else 'failure'
validation.report = json.dumps(report)
else:
validation.status = 'error'
validation.report = json.dumps(report)
if 'tables' in report:
if 'errors' in report and report['errors']:
validation.status = 'error'
validation.error = {
'message': [str(err) for err in report['tables'][0]['errors']] if len(report['tables'][0]['errors']) > 0 else 'No tables found'}
'message': [str(err) for err in report['errors']]}
else:
validation.error = {'message': ['Error running validation']}
validation.error = {'message': ['Errors validating the data']}
validation.finished = datetime.datetime.utcnow()

Session.add(validation)
Expand All @@ -135,7 +136,6 @@ def run_validation_job(resource):




def _validate_table(source, _format='csv', schema=None, **options):

# This option is needed to allow Frictionless Framework to validate absolute paths
Expand Down
2 changes: 2 additions & 0 deletions ckanext/validation/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
validation_extract_report_from_errors,
dump_json_value,
bootstrap_version,
validation_dict,
use_webassets,
)
from ckanext.validation.validators import (
Expand Down Expand Up @@ -110,6 +111,7 @@ def get_helpers(self):
u'validation_extract_report_from_errors': validation_extract_report_from_errors,
u'dump_json_value': dump_json_value,
u'bootstrap_version': bootstrap_version,
u'validation_dict': validation_dict,
u'use_webassets': use_webassets,
}

Expand Down
4 changes: 2 additions & 2 deletions ckanext/validation/templates/scheming/snippets/errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

{% if validation_report %}
{% if h.bootstrap_version() == '3' %}
{% snippet 'validation/snippets/validation_report_dialog.html', validation_report=validation_report %}
{% snippet 'validation/snippets/validation_report_dialog.html', validation_report=h.dump_json_value(validation_report) %}
{% else %}
{% snippet 'validation/snippets/validation_report_dialog_bs2.html', validation_report=validation_report %}
{% snippet 'validation/snippets/validation_report_dialog_bs2.html', validation_report=h.dump_json_value(validation_report) %}
{% endif %}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h3>
</h3>
</div>
<div class="modal-body">
<div id="report" data-module="validation-report" data-module-report="{{ h.dump_json_value(validation_report) }}"></div>
<div id="report" data-module="validation-report" data-module-report="{{ validation_report }}"></div>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions ckanext/validation/templates/validation/validation_read.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ <h1 class="page-heading">{{ h.resource_display_name(resource) | truncate(50) }}
<div class="validation-details">
<div>{{ _('Validation timestamp') }}: {{ h.render_datetime(resource.validation_timestamp, with_hours=True) }}</div>
{% if validation.report %}
<div>{{ _('Duration') }}: {{ validation.report.time }}s</div>
<div>{{ _('Duration') }}: {{ h.validation_dict(validation.report)["stats"]["seconds"] }}s</div>
{% endif %}
</div>

{% if validation.report %}
<div id="report" {% if h.bootstrap_version() == '2' %}class="bs2"{% endif %} data-module="validation-report" data-module-report="{{ h.dump_json_value(validation.report) }}"></div>
<div id="report" {% if h.bootstrap_version() == '2' %}class="bs2"{% endif %} data-module="validation-report" data-module-report="{{ validation.report }}"></div>
{% endif %}

</div>
Expand Down
2 changes: 1 addition & 1 deletion ckanext/validation/tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_job_run_error_stores_validation_object(self, mock_validate):
)

assert validation.status == "error"
assert validation.error == {"message": ['Error running validation']}
assert validation.error == {"message": ['Errors validating the data']}
assert validation.finished

@mock.patch(
Expand Down
5 changes: 3 additions & 2 deletions ckanext/validation/webassets/js/module-modal-dialog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
this.ckan.module('modal-dialog', function (jQuery) {
"use strict";

ckan.module('modal-dialog', function (jQuery) {
return {

/* holds the loaded lightbox */
Expand All @@ -15,7 +17,6 @@ this.ckan.module('modal-dialog', function (jQuery) {
*/
initialize: function () {
jQuery.proxyAll(this, /_on/);

this.el.on('click', this._onClick);
this.modal = $('#' + this.options.div)
},
Expand Down
12 changes: 6 additions & 6 deletions ckanext/validation/webassets/js/module-validation-report.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
this.ckan.module('validation-report', function (jQuery) {
"use strict";

ckan.module('validation-report', function (jQuery) {
return {
options: {
report: null
},
initialize: function() {
goodtablesUI.render(
goodtablesUI.Report,
{report: this.options.report},
this.el[0]
)
let element = document.getElementById('report')
let report = this.options.report
frictionlessComponents.render(frictionlessComponents.Report, { report }, element)
}
}
});
Loading

0 comments on commit fff8dc5

Please sign in to comment.