Commit 675bf91d authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Now call goodtables validator

parent 3fe651d6
......@@ -26,6 +26,7 @@ setup(
......@@ -6,6 +6,15 @@ from pathlib import Path
import requests
import ujson as json
from validata_validate import validate
from goodtables import Inspector
# MEMENTO: json.load(pkg_resources.resource_stream('validata_validate', 'spec.json'))
class ValidatorHelper:
......@@ -77,11 +86,23 @@ class ValidatorHelper:
return [cls.schema_info(code) for code in sorted(cls.schema_dict.keys())]
def validate_url(cls, schema_code, url):
""" TODO: validate URL against schema """
print('Validate url [{}] against schema {}'.format(url, schema_code))
def validate_file(cls, schema_code, file):
""" TODO: validate file agains schema """
print('Validate file [{}] against schema {}'.format(file, schema_code))
def validate(cls, schema_code, source, res_type):
""" Validate source against schema using custom-checks """
# Gets schema info
sc_info = cls.schema_dict[schema_code]
# Build checks configuration
checks = ['structure', 'schema']
if 'custom_checks' in sc_info:
for check_conf in sc_info['custom_checks']['checks']:
checks.append({check_conf['name']: check_conf['params']})
inspector = Inspector(checks=checks, row_limit=VALIDATA_MAX_ROWS)
return validate(
......@@ -11,19 +11,14 @@ from validata_ui_next import app
from validata_ui_next.util import flash_error, flash_info, flash_success, flash_warning
from validata_ui_next.validate import ValidatorHelper
from flask import Flask, flash, redirect, render_template, request, url_for
from flask import Flask, jsonify, redirect, render_template, request, url_for
def validate_url(schema_code, url):
ValidatorHelper.validate_url(schema_code, url)
return "TODO: valider l'url "+url
# return render_template('validation_report.html')
def validate(schema_code, source, res_type):
report = ValidatorHelper.validate(schema_code, source, res_type)
return jsonify(report)
def validate_file(schema_code, file):
ValidatorHelper.validate_file(schema_code, file)
return "TODO: valider le fichier "+file
# return render_template('validation_report.html')
# Routes
......@@ -73,7 +68,7 @@ def scdl_validator(val_code):
if url is None or url == '':
flash_error("Vous n'avez pas indiqué d'url à valider")
return redirect(url_for('scdl_validator', val_code=val_code))
return validate_url(val_code, url)
return validate(val_code, url, 'url')
else: # POST
input_param = request.form.get('input')
......@@ -87,7 +82,8 @@ def scdl_validator(val_code):
if f is None:
flash_warning("Vous n'avez pas indiqué de fichier à valider")
return redirect(url_for('scdl_validator', val_code=val_code))'/tmp', f.filename))
return validate_file(val_code, f.filename)
fpath = os.path.join('/tmp', f.filename)
return validate(val_code, fpath, 'file')
return 'Bizarre, vous avez dit bizarre ?'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment