Commit a5effda7 authored by Pierre Dittgen's avatar Pierre Dittgen

Remove unused ValidatorHelper class

parent bc267bff
......@@ -5,15 +5,9 @@ from urllib.parse import quote_plus
import flask
import jinja2
#import validata_core
# Let this import after app initialisation
from . import config
#from .validate_helper import ValidatorHelper
# Schemas settings
# schemas_config = validata_core.get_schemas_config()
# ValidatorHelper.init(schemas_config)
# TODO: load config.toml
......
""" Call validation code """
import logging
import validata_core
log = logging.getLogger(__name__)
class ValidatorHelper:
""" Help validating tabular data """
schema_dict = {}
@classmethod
def init(cls, schemas_config):
""" Register and download schema and custom_checks info """
cls.validator = validata_core.Validator(schemas_config)
cls.schema_dict = {}
for code, schema_config in schemas_config.items():
schema = schema_config['schema']
log.info('Loading schema %r from %r', code, schema)
schema_instance = cls.validator.load_schema(schema)
if schema_instance:
cls.schema_dict[code] = {**schema_config, "schema_instance": schema_instance}
@classmethod
def schema_exist(cls, schema_code):
""" Checks if schema exists """
return schema_code in cls.schema_dict
@classmethod
def schema_info(cls, schema_code):
""" Return schema info from code """
if not cls.schema_exist(schema_code):
return None
# First schema keys but 'fields'
d1 = {
k: v
for k, v in cls.schema(schema_code).descriptor.items()
if k != 'fields'
}
# All keys but schema* and custom_checks*
d2 = {k: v for k, v in cls.schema_dict[schema_code].items()
if not k.startswith('schema')}
return {**d1, 'code': schema_code, **d2}
@classmethod
def schema(cls, schema_code):
""" Return schema from schema code """
if not cls.schema_exist(schema_code):
return None
return cls.schema_dict[schema_code]['schema_instance']
@classmethod
def schema_info_list(cls):
""" Computes and return schema info list """
return [cls.schema_info(code) for code in sorted(cls.schema_dict.keys())]
@classmethod
def validate(cls, schema_url, **options):
"""Validate"""
return cls.validator.validate(schema=schema_url, **options)
......@@ -25,7 +25,6 @@ import tabulator
from . import app, config
from .ui_util import flash_error, flash_warning
from .validata_util import ValidataSource
from .validate_helper import ValidatorHelper
MonkeyPatch.patch_fromisoformat()
......@@ -326,7 +325,6 @@ def bytes_data(f):
@app.route('/')
def home():
""" Home page """
validators = ValidatorHelper.schema_info_list()
external_validators = [
{
"title": "INSPIRE",
......@@ -345,7 +343,7 @@ def home():
},
]
flash_warning('Ce service est fourni en mode beta - certains problèmes peuvent subsister - nous mettons tout en œuvre pour améliorer son fonctionnement en continu.')
return render_template('home.html', title='Accueil', validators=validators, external_validators=external_validators)
return render_template('home.html', title='Accueil', validators=[], external_validators=external_validators)
@app.route('/validators')
......
Markdown is supported
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