Commit aca3cd31 authored by Pierre Dittgen's avatar Pierre Dittgen

schema can be expressed as name,ref or url

parent f8ba2b03
[ {
"sections": [
{ {
"code": "scdl", "code": "scdl",
"title": "Validateurs SCDL", "title": "Validateurs SCDL",
"catalog": [ "catalog": "https://git.opendatafrance.net/scdl/schema-catalog/raw/master/schema_catalog.toml"
{
"code": "scdl-adresses",
"title": "Adresses locales",
"description": "Liste des adresses locales d'une collectivité",
"schema_url": "https://git.opendatafrance.net/scdl/adresses/raw/v1.1.3/schema.json",
"doc_url": "https://scdl.opendatafrance.net/docs/schemas/scdl-adresses.html"
},
{
"code": "scdl-catalogue",
"title": "Catalogue simplifié",
"description": "Liste des jeux de données publiés en open data par une collectivité",
"schema_url": "https://git.opendatafrance.net/scdl/catalogue/raw/v0.1.1/schema.json",
"doc_url": "https://scdl.opendatafrance.net/docs/schemas/scdl-catalogue.html"
},
{
"code": "scdl-deliberations",
"title": "Délibérations",
"description": "Liste des délibérations adoptées par une assemblée locale",
"schema_url": "https://git.opendatafrance.net/scdl/deliberations/raw/v2.1.2/schema.json",
"doc_url": "https://scdl.opendatafrance.net/docs/schemas/scdl-deliberations.html"
},
{
"code": "scdl-equipements",
"title": "Equipements",
"description": "Liste des équipements collectifs publics d'une collectivité",
"schema_url": "https://git.opendatafrance.net/scdl/equipements/raw/v0.1.0/schema.json",
"doc_url": "https://scdl.opendatafrance.net/docs/schemas/scdl-equipements.html"
},
{
"code": "scdl-irve",
"title": "Infrastructures de recharge de véhicule électrique",
"description": "Liste des infrastructures de recharge de véhicules électriques d'une collectivité",
"schema_url": "https://raw.githubusercontent.com/OpenDataFrance/schema.data.gouv.fr/master/irve/schema.json",
"doc_url": "https://scdl.opendatafrance.net/docs/schemas/scdl-irve.html"
},
{
"code": "scdl-marches-publics",
"title": "Marchés publics",
"description": "Liste des marchés publics attribués par une collectivité",
"schema_url": "https://git.opendatafrance.net/scdl/marches-publics/raw/v2.0.0/schema.json",
"doc_url": "https://scdl.opendatafrance.net/docs/schemas/scdl-marches-publics.html"
},
{
"code": "scdl-prenoms",
"title": "Prénoms des nouveaux-nés",
"description": "Liste des prénoms des nouveaux-nés déclarés à l'état-civil",
"schema_url": "https://github.com/OpenDataFrance/liste-prenoms-nouveaux-nes/raw/v1.1.3/schema.json",
"doc_url": "https://scdl.opendatafrance.net/docs/schemas/scdl-prenoms.html"
},
{
"code": "scdl-subventions",
"title": "Subventions",
"description": "Liste des subventions publiques attribuées par une collectivité",
"schema_url": "https://git.opendatafrance.net/scdl/subventions/raw/v2.0.0/schema.json",
"doc_url": "https://scdl.opendatafrance.net/docs/schemas/scdl-subventions.html"
}
]
}, },
{ {
"code": "external", "code": "external",
"title": "Validateurs externes", "title": "Validateurs externes",
"catalog": [ "catalog": [
{ {
"code": "inspire", "name": "inspire",
"type": "external", "type": "external",
"title": "INSPIRE", "title": "INSPIRE",
"description": "proposé par la Commission Européenne pour tester des ressources géographiques (données, services ou métadonnées)", "description": "proposé par la Commission Européenne pour tester des ressources géographiques (données, services ou métadonnées)",
"website": "http://inspire-sandbox.jrc.ec.europa.eu/validator/" "website": "http://inspire-sandbox.jrc.ec.europa.eu/validator/"
}, },
{ {
"code": "bal", "name": "bal",
"type": "external", "type": "external",
"title": "BAL", "title": "BAL",
"description": "proposé par la mission Etalab pour tester des données Adresse produites localement (format BAL 1.1)", "description": "proposé par la mission Etalab pour tester des données Adresse produites localement (format BAL 1.1)",
"website": "https://adresse.data.gouv.fr/bases-locales/validateur" "website": "https://adresse.data.gouv.fr/bases-locales/validateur"
}, },
{ {
"code": "cvdtc", "name": "cvdtc",
"type": "external", "type": "external",
"title": "CVDTC", "title": "CVDTC",
"description": "proposé par l'AFIMB dans le cadre du projet Chouette pour tester des données de transport collectif (GTFS ou NEPTUNE)", "description": "proposé par l'AFIMB dans le cadre du projet Chouette pour tester des données de transport collectif (GTFS ou NEPTUNE)",
"website": "http://www.conversion-validation-donnees-tc.org/" "website": "http://www.conversion-validation-donnees-tc.org/"
} }
] ]
} }
] ]
\ No newline at end of file }
...@@ -3,19 +3,34 @@ import os ...@@ -3,19 +3,34 @@ import os
from pathlib import Path from pathlib import Path
from urllib.parse import quote_plus from urllib.parse import quote_plus
import opendataschema
import flask import flask
import jinja2 import jinja2
import requests
import tableschema
from cachetools.func import ttl_cache
# Let this import after app initialisation # Let this import after app initialisation
from . import config from . import config
# TODO: load config.toml
@ttl_cache(maxsize=20*1024, ttl=5*60)
def download_with_cache(url):
return requests.get(url)
@ttl_cache(maxsize=20*1024, ttl=5*60)
def schema_from_url(url):
return tableschema.Schema(url)
# load config.json and catalog_schema_toml
ui_config = json.load(config.UI_CONFIG_FILE.open('rt', encoding='utf-8')) if config.UI_CONFIG_FILE else [] ui_config = json.load(config.UI_CONFIG_FILE.open('rt', encoding='utf-8')) if config.UI_CONFIG_FILE else []
schema_info_map = {} # super ugly way to access catalog_toml url
for section in ui_config: schema_catalog_url = ui_config['sections'][0]['catalog']
for val in section['catalog']: table_schema_catalog = opendataschema.TableSchemaCatalog(schema_catalog_url, download_func=download_with_cache)
if 'schema_url' in val:
schema_info_map[val['schema_url']] = val
# Flask things # Flask things
app = flask.Flask(__name__) app = flask.Flask(__name__)
......
...@@ -4,7 +4,7 @@ block head %} ...@@ -4,7 +4,7 @@ block head %}
{% endblock %} {% block content %} {% endblock %} {% block content %}
<h1 class="my-4">Validez vos jeux de données</h1> <h1 class="my-4">Validez vos jeux de données</h1>
{% for section in config %} {% for section in config.sections %}
<h2>{{section.title}}</h2> <h2>{{section.title}}</h2>
<div class="row my-4"> <div class="row my-4">
{% for val in section.catalog %} {% for val in section.catalog %}
...@@ -31,7 +31,7 @@ block head %} ...@@ -31,7 +31,7 @@ block head %}
<h4 class="card-title">{{ val.title }}</h4> <h4 class="card-title">{{ val.title }}</h4>
<p class="card-text">{{ val.description }}</p> <p class="card-text">{{ val.description }}</p>
<a <a
href="{{ url_for('custom_validator') }}?schema={{val.schema_url|urlencode}}" href="{{ url_for('custom_validator') }}?schema_name={{val.name}}"
class="btn btn-primary mt-auto" class="btn btn-primary mt-auto"
>Choisir</a >Choisir</a
> >
...@@ -49,10 +49,10 @@ block head %} ...@@ -49,10 +49,10 @@ block head %}
<div class="form-group"> <div class="form-group">
<label for="schema">Indiquez ici l'URL du schéma de validation à utiliser</label> <label for="schema">Indiquez ici l'URL du schéma de validation à utiliser</label>
<input <input
name="schema" name="schema_url"
type="url" type="url"
class="form-control" class="form-control"
id="schema" id="schema_url"
aria-describedby="urlHelp" aria-describedby="urlHelp"
placeholder="https://..." placeholder="https://..."
/> />
......
<h5 class="card-title"> <h5 class="card-title">
Schéma Schéma
{% if val_info.title %} {% if schema_info.title %}
« {{ val_info.title }} » « {{ schema_info.title }} »
{% endif %} {% endif %}
{#
<span class="badge badge-primary">{{ val_info.version }}</span>
#}
</h5> </h5>
{% if val_info.description %} {% if schema_info.description %}
<h6 class="card-subtitle mb-2 text-muted">{{ val_info.description }}</h6> <h6 class="card-subtitle mb-2 text-muted">{{ schema_info.description }}</h6>
{% endif %} {% endif %}
{% if val_info.author or val_info.contributor %} {% if schema_info.author or schema_info.contributor %}
<p> <p>
{% if val_info.author %} {% if schema_info.author %}
Auteur : {{ val_info.author }} Auteur : {{ schema_info.author }}
{% endif %} {% endif %}
{% if val_info.contributor %} {% if schema_info.contributor %}
<br />Contributeur(s) : {{ val_info.contributor }} <br />Contributeur(s) : {{ schema_info.contributor }}
{% endif %} {% endif %}
</p> </p>
{% endif %} {% endif %}
<p> <p>
{% if val_info.doc_url %} {% if schema_info.doc_url %}
<a href="{{ val_info.doc_url }}" target="_blank" class="card-link">Documentation</a> <a href="{{ schema_info.doc_url }}" target="_blank" class="card-link">Documentation</a>
{% else %} {% else %}
<a href="{{ schema_url }}" target="_blank" class="card-link">{{ schema_url }}</a> <a href="{{ schema_info.url }}" target="_blank" class="card-link">{{ schema_info.url }}</a>
{% endif %} {% endif %}
</p> </p>
...@@ -26,19 +26,15 @@ block head %} ...@@ -26,19 +26,15 @@ block head %}
<a class="nav-link" id="url-tab" data-toggle="tab" href="#url" role="tab" aria-controls="url" <a class="nav-link" id="url-tab" data-toggle="tab" href="#url" role="tab" aria-controls="url"
aria-selected="false">URL</a> aria-selected="false">URL</a>
</li> </li>
{#
<li class="nav-item">
<a class="nav-link" id="examples-tab" data-toggle="tab" href="#example" role="tab" aria-controls="examples"
aria-selected="false">Exemples</a>
</li>
#}
</ul> </ul>
{% set padding_class = 'p-3' %} {% set padding_class = 'p-3' %}
<div class="tab-content" id="myTabContent"> <div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active {{ padding_class }}" id="file" role="tabpanel" aria-labelledby="file-tab"> <div class="tab-pane fade show active {{ padding_class }}" id="file" role="tabpanel" aria-labelledby="file-tab">
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data">
<input type="hidden" name="input" value="file" /> <input type="hidden" name="input" value="file" />
<input type="hidden" name="schema" value="{{ schema_url }}" /> {% for key, value in schema_params.items() %}
<input type="hidden" name="{{ key }}" value="{{ value }}" />
{% endfor %}
<div class="form-group"> <div class="form-group">
<label for="file">Choisissez un fichier tabulaire à valider (.xlsx, .xls, .ods, .csv, .tsv, <label for="file">Choisissez un fichier tabulaire à valider (.xlsx, .xls, .ods, .csv, .tsv,
etc.)</label> etc.)</label>
...@@ -50,7 +46,9 @@ block head %} ...@@ -50,7 +46,9 @@ block head %}
<div class="tab-pane fade {{ padding_class }}" id="url" role="tabpanel" aria-labelledby="url-tab"> <div class="tab-pane fade {{ padding_class }}" id="url" role="tabpanel" aria-labelledby="url-tab">
<form method="GET"> <form method="GET">
<input type="hidden" name="input" value="url" /> <input type="hidden" name="input" value="url" />
<input type="hidden" name="schema" value="{{ schema_url }}" /> {% for key, value in schema_params.items() %}
<input type="hidden" name="{{ key }}" value="{{ value }}" />
{% endfor %}
<div class="form-group"> <div class="form-group">
<label for="url">Indiquez l'URL de la table à valider</label> <label for="url">Indiquez l'URL de la table à valider</label>
<input name="url" type="url" class="form-control" id="url" aria-describedby="urlHelp" <input name="url" type="url" class="form-control" id="url" aria-describedby="urlHelp"
...@@ -60,23 +58,6 @@ block head %} ...@@ -60,23 +58,6 @@ block head %}
<button type="submit" class="btn btn-primary">Valider</button> <button type="submit" class="btn btn-primary">Valider</button>
</form> </form>
</div> </div>
{#
<div class="tab-pane fade {{ padding_class }}" id="example" role="tabpanel" aria-labelledby="examples-tab">
<form method="GET">
<input type="hidden" name="input" value="example" />
<div class="form-group">
<label for="url">Choisissez l'exemple à valider</label>
<select name="url" id="example" class="form-control">
<option value="">...</option>
{% for example in val_info.examples %}
<option value="{{ example.url }}">{{ example.name }}</option>
{% endfor %}
</select>
</div>
<button type="submit" class="btn btn-primary">Valider</button>
</form>
</div>
#}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
{% endif %} {% endif %}
{% if source.type == 'url' %} {% if source.type == 'url' %}
<p class="hidden-print"> <p class="hidden-print">
<a href="{{ url_for('pdf_report') }}?schema={{schema_url|urlencode}}&url={{source.name|urlencode}}" target="_blank"> <a href="{{ pdf_report_url }}&url={{source.name|urlencode}}" target="_blank">
Télécharger en PDF Télécharger en PDF
</a> </a>
</p> </p>
......
This diff is collapsed.
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