Commit 3fe651d6 authored by Pierre Dittgen's avatar Pierre Dittgen

Merge schema info

parent e38c6584
......@@ -16,7 +16,7 @@ pip install -e .
Start the web server:
```bash
export FLASK_APP=validata-ui-next
export FLASK_APP=validata_ui_next
export FLASK_ENV=development
flask run
* Running on http://127.0.0.1:5000/
......
......@@ -9,23 +9,95 @@ from validata_ui_next.validate import ValidatorHelper
schemas_config = {
"scdl-adresses": {
"schema_json_url": "https://git.opendatafrance.net/scdl/adresses/raw/master/schema-scdl-adresses.json",
"custom_checks_json_url": "https://git.opendatafrance.net/scdl/adresses/raw/master/custom-checks.json"
"custom_checks_json_url": "https://git.opendatafrance.net/scdl/adresses/raw/master/custom-checks.json",
"title": "Adresses locales",
"description": "Liste des adresses locales d'une collectivité",
"specurl": "http://www.opendatafrance.net/SCDL_Adresses_Locales",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-adresses.md",
"examples": [
{
"name": "Adresses fictives invalides",
"url": "https://git.opendatafrance.net/scdl/adresses/raw/v1.1/exemples/exemple_invalide.csv"
},
{
"name": "Adresses de Bayonne avril 2018",
"url": "https://git.opendatafrance.net/scdl/adresses/raw/v1.1/exemples/20180424_bal_216401026.csv"
}
]
},
"scdl-deliberations": {
"schema_json_url": "https://git.opendatafrance.net/scdl/deliberations/raw/master/schema.json",
"custom_checks_json_url": "https://git.opendatafrance.net/scdl/deliberations/raw/master/custom-checks.json"
"custom_checks_json_url": "https://git.opendatafrance.net/scdl/deliberations/raw/master/custom-checks.json",
"title": "Délibérations",
"description": "Liste des délibérations adoptées par une assemblée locale",
"specurl": "http://www.opendatafrance.net/SCDL_Deliberations",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-deliberations.md",
"examples": [
{
"name": "Délibérations fictives valides",
"url": "https://git.opendatafrance.net/scdl/deliberations/raw/v2.0/examples/Deliberations_ok.csv"
},
{
"name": "Délibérations fictives invalides",
"url": "https://git.opendatafrance.net/scdl/deliberations/raw/v2.0/examples/DeliberationsCindoc.csv"
}
]
},
"scdl-marches-publics": {
"schema_json_url": "https://git.opendatafrance.net/scdl/marches-publics/raw/pdi/schema.json",
"custom_checks_json_url": "https://git.opendatafrance.net/scdl/marches-publics/raw/pdi/custom-checks.json"
"custom_checks_json_url": "https://git.opendatafrance.net/scdl/marches-publics/raw/pdi/custom-checks.json",
"title": "Marchés publics",
"description": "Liste des marchés publics attribués par une collectivité",
"specurl": "http://www.opendatafrance.net/SCDL_Marches_Publics",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-marches.md",
"examples": [
{
"name": "Marchés publics fictifs valides",
"url": "https://git.opendatafrance.net/scdl/marches-publics/raw/master/exemples/exemple_marche_public.csv"
},
{
"name": "Marchés publics fictifs invalides",
"url": "https://git.opendatafrance.net/scdl/marches-publics/raw/master/exemples/exemple_marche_public_avec_erreurs.csv"
}
]
},
"scdl-prenoms": {
"schema_json_url": "https://github.com/CharlesNepote/liste-prenoms-nouveaux-nes/raw/v1.1.1/prenom-schema.json",
# "custom_checks_json_url": "https://git.opendatafrance.net/scdl/prenoms/raw/master/custom-checks.json"
# "custom_checks_json_url": "https://git.opendatafrance.net/scdl/prenoms/raw/master/custom-checks.json",
"title": "Prénoms des nouveaux-nés",
"description": "Liste des prénoms des nouveaux-nés déclarés à l'état-civil",
"specurl": "https://docs.google.com/document/d/1Vk0kpBw3MIocai9JqovLK2HxcUA_3QHnZicqxuOpcQ8/edit?usp=sharing",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-prenoms.md",
"examples": [
{
"name": "Prénoms des nouveaux-nés Digne-les-Bains 2017",
"url": "https://raw.githubusercontent.com/CharlesNepote/liste-prenoms-nouveaux-nes/v1.1.1/DIGNE-PRENOMS-2017.csv"
},
{
"name": "Prénoms des nouveaux-nés fictifs invalides",
"url": "https://raw.githubusercontent.com/CharlesNepote/liste-prenoms-nouveaux-nes/v1.1.1/prenoms-nouveaux-nes.exemple.invalide.1.1.csv"
}
]
},
"scdl-subventions": {
"schema_json_url": "https://git.opendatafrance.net/scdl/subventions/raw/master/schema.json",
"custom_checks_json_url": "https://git.opendatafrance.net/scdl/subventions/raw/master/custom-checks.json"
"custom_checks_json_url": "https://git.opendatafrance.net/scdl/subventions/raw/master/custom-checks.json",
"title": "Subventions",
"description": "Liste des subventions publiques attribuées par une collectivité",
"specurl": "http://www.opendatafrance.net/SCDL_Subventions",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-subventions.md",
"examples": [
{
"name": "Subventions fictives invalides",
"url": "https://git.opendatafrance.net/scdl/subventions/raw/v1.1/exemples/exemple_invalide.csv"
},
{
"name": "Erreur de format (HTML au lieu de CSV)",
"url": "https://git.opendatafrance.net/"
}
]
},
}
ValidatorHelper.init(schemas_config, Path('/tmp'))
......
{
"scdl-adresses": {
"title": "Adresses locales",
"description": "Liste des adresses locales d'une collectivité",
"specurl": "http://www.opendatafrance.net/SCDL_Adresses_Locales",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-adresses.md",
"examples": [
{
"name": "Adresses fictives invalides",
"url": "https://git.opendatafrance.net/scdl/adresses/raw/v1.1/exemples/exemple_invalide.csv"
},
{
"name": "Adresses de Bayonne avril 2018",
"url": "https://git.opendatafrance.net/scdl/adresses/raw/v1.1/exemples/20180424_bal_216401026.csv"
}
]
},
"scdl-deliberations": {
"title": "Délibérations",
"description": "Liste des délibérations adoptées par une assemblée locale",
"specurl": "http://www.opendatafrance.net/SCDL_Deliberations",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-deliberations.md",
"examples": [
{
"name": "Délibérations fictives valides",
"url": "https://git.opendatafrance.net/scdl/deliberations/raw/v2.0/examples/Deliberations_ok.csv"
},
{
"name": "Délibérations fictives invalides",
"url": "https://git.opendatafrance.net/scdl/deliberations/raw/v2.0/examples/DeliberationsCindoc.csv"
}
]
},
"scdl-marches-publics": {
"title": "Marchés publics",
"description": "Liste des marchés publics attribués par une collectivité",
"specurl": "http://www.opendatafrance.net/SCDL_Marches_Publics",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-marches.md",
"examples": [
{
"name": "Marchés publics fictifs valides",
"url": "https://git.opendatafrance.net/scdl/marches-publics/raw/master/exemples/exemple_marche_public.csv"
},
{
"name": "Marchés publics fictifs invalides",
"url": "https://git.opendatafrance.net/scdl/marches-publics/raw/master/exemples/exemple_marche_public_avec_erreurs.csv"
}
]
},
"scdl-prenoms": {
"title": "Prénoms des nouveaux-nés",
"description": "Liste des prénoms des nouveaux-nés déclarés à l'état-civil",
"specurl": "https://docs.google.com/document/d/1Vk0kpBw3MIocai9JqovLK2HxcUA_3QHnZicqxuOpcQ8/edit?usp=sharing",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-prenoms.md",
"examples": [
{
"name": "Prénoms des nouveaux-nés Digne-les-Bains 2017",
"url": "https://raw.githubusercontent.com/CharlesNepote/liste-prenoms-nouveaux-nes/v1.1.1/DIGNE-PRENOMS-2017.csv"
},
{
"name": "Prénoms des nouveaux-nés fictifs invalides",
"url": "https://raw.githubusercontent.com/CharlesNepote/liste-prenoms-nouveaux-nes/v1.1.1/prenoms-nouveaux-nes.exemple.invalide.1.1.csv"
}
]
},
"scdl-subventions": {
"title": "Subventions",
"description": "Liste des subventions publiques attribuées par une collectivité",
"specurl": "http://www.opendatafrance.net/SCDL_Subventions",
"docurl": "https://git.opendatafrance.net/validata/validata-doc/blob/master/static/schemas/scdl-subventions.md",
"examples": [
{
"name": "Subventions fictives invalides",
"url": "https://git.opendatafrance.net/scdl/subventions/raw/v1.1/exemples/exemple_invalide.csv"
},
{
"name": "Erreur de format (HTML au lieu de CSV)",
"url": "https://git.opendatafrance.net/"
}
]
}
}
\ No newline at end of file
......@@ -59,8 +59,17 @@ class ValidatorHelper:
""" Return schema info from code """
if not cls.schema_exist(schema_code):
return None
d = dict([(k, v) for k, v in cls.schema_dict[schema_code]['schema'].items() if k != 'fields'])
return {**d, 'code': schema_code}
# First schema keys but 'fields'
d1 = dict([(k, v) for k, v in cls.schema_dict[schema_code]['schema'].items() if k != 'fields'])
print('D1 =', d1)
# 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') and not k.startswith('custom_checks')}
print('D2 =', d2)
return {**d1, 'code': schema_code, **d2}
@classmethod
def schema_info_list(cls):
......
......@@ -25,25 +25,13 @@ def validate_file(schema_code, file):
return "TODO: valider le fichier "+file
# return render_template('validation_report.html')
# Supplementary schema info
SCHEMA_ADDON_FILE = Path(__file__).parent / 'static/data/scdl-addon-info.json'
SCHEMA_ADDON_INFO = json.load(SCHEMA_ADDON_FILE.open('rt', encoding='utf-8'))
def suppl_schema_info(d):
""" Add editorial info to schema info"""
code = d['code']
return {**d, **SCHEMA_ADDON_INFO[code]} if code in SCHEMA_ADDON_INFO else d
# Routes
@app.route('/')
def home():
""" Home page """
validators = list(map(suppl_schema_info, ValidatorHelper.schema_info_list()))
validators = ValidatorHelper.schema_info_list()
return render_template('home.html', title='Accueil', validators=validators)
......@@ -70,7 +58,7 @@ def scdl_validator(val_code):
if request.method == 'GET':
val_info = suppl_schema_info(ValidatorHelper.schema_info(val_code))
val_info = ValidatorHelper.schema_info(val_code)
input_param = request.args.get('input')
# First form display
......
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