Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
V
validata-ui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
20
Issues
20
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Validata
validata-ui
Commits
66943441
Commit
66943441
authored
Jun 04, 2019
by
Pierre Dittgen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use config.json
parent
a5effda7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
296 additions
and
225 deletions
+296
-225
.env.example
.env.example
+4
-1
config.json.example
config.json.example
+91
-0
validata_ui/__init__.py
validata_ui/__init__.py
+7
-1
validata_ui/config.py
validata_ui/config.py
+5
-0
validata_ui/templates/home.html
validata_ui/templates/home.html
+45
-34
validata_ui/templates/schema_info_part.html
validata_ui/templates/schema_info_part.html
+31
-0
validata_ui/templates/validation_form.html
validata_ui/templates/validation_form.html
+73
-134
validata_ui/templates/validation_report.html
validata_ui/templates/validation_report.html
+2
-19
validata_ui/views.py
validata_ui/views.py
+38
-36
No files found.
.env.example
View file @
66943441
...
...
@@ -8,4 +8,7 @@ BADGE_CONFIG_URL="https://git.opendatafrance.net/validata/validata-badge/raw/mas
SHIELDS_IO_BASE_URL="https://img.shields.io/"
# Validata API endpoint
API_VALIDATE_ENDPOINT=http://127.0.0.1:5600/validate
\ No newline at end of file
API_VALIDATE_ENDPOINT=http://127.0.0.1:5600/validate
# UI config file path
UI_CONFIG_FILE=config.json
\ No newline at end of file
config.json.example
0 → 100644
View file @
66943441
[
{
"code": "scdl",
"title": "Validateurs SCDL",
"catalog": [
{
"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",
"title": "Validateurs externes",
"catalog": [
{
"code": "inspire",
"type": "external",
"title": "INSPIRE",
"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/"
},
{
"code": "bal",
"type": "external",
"title": "BAL",
"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"
},
{
"code": "cvdtc",
"type": "external",
"title": "CVDTC",
"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/"
}
]
}
]
\ No newline at end of file
validata_ui/__init__.py
View file @
66943441
import
json
import
os
from
pathlib
import
Path
from
urllib.parse
import
quote_plus
...
...
@@ -9,7 +10,12 @@ import jinja2
from
.
import
config
# TODO: load config.toml
ui_config
=
json
.
load
(
config
.
UI_CONFIG_FILE
.
open
(
'rt'
,
encoding
=
'utf-8'
))
if
config
.
UI_CONFIG_FILE
else
[]
schema_info_map
=
{}
for
section
in
ui_config
:
for
val
in
section
[
'catalog'
]:
if
'schema_url'
in
val
:
schema_info_map
[
val
[
'schema_url'
]]
=
val
# Flask things
app
=
flask
.
Flask
(
__name__
)
...
...
validata_ui/config.py
View file @
66943441
import
logging
import
os
from
pathlib
import
Path
import
requests
import
toml
...
...
@@ -31,3 +32,7 @@ else:
SHIELDS_IO_BASE_URL
=
os
.
environ
.
get
(
"SHIELDS_IO_BASE_URL"
)
or
None
if
SHIELDS_IO_BASE_URL
and
not
SHIELDS_IO_BASE_URL
.
endswith
(
'/'
):
SHIELDS_IO_BASE_URL
+=
'/'
UI_CONFIG_FILE
=
os
.
environ
.
get
(
"UI_CONFIG_FILE"
)
or
None
if
UI_CONFIG_FILE
:
UI_CONFIG_FILE
=
Path
(
UI_CONFIG_FILE
)
validata_ui/templates/home.html
View file @
66943441
...
...
@@ -4,50 +4,61 @@ block head %}
{% endblock %} {% block content %}
<h1
class=
"my-4"
>
Validez vos jeux de données
</h1>
<h2>
Validateurs
<span
abbr=
"Socle commun des données locales"
>
SCDL
</span></h2>
{% for section in config %}
<h2>
{{section.title}}
</h2>
<div
class=
"row my-4"
>
{% for val in validators %}
<div
class=
"col-sm-4 col-md-3 mb-4"
>
<div
class=
"card text-center h-100"
>
<div
class=
"card-body d-flex flex-column"
>
<h4
class=
"card-title"
>
{{ val.title }}
</h4>
<p
class=
"card-text"
>
{{ val.description }}
</p>
<a
href=
"{{ url_for('scdl_validator', val_code=val.code) }}"
class=
"btn btn-primary mt-auto"
>
Choisir
</a
>
{% for val in section.catalog %}
{% if val.website %}
<div
class=
"col-sm-4 col-md-3 mb-4"
>
<div
class=
"card text-center h-100"
>
<div
class=
"card-body d-flex flex-column"
>
<h4
class=
"card-title"
>
{{ val.title }}
</h4>
<p
class=
"card-text"
>
{{ val.description }}
</p>
<a
href=
"{{ val.website }}"
target=
"_blank"
class=
"btn btn-primary mt-auto"
>
Voir
<i
class=
"fas fa-external-link-alt ml-1"
></i>
</a
>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
<h2>
Validateurs externes
</h2>
<div
class=
"row my-4"
>
{% for val in external_validators %}
<div
class=
"col-sm-4 col-md-3 mb-4"
>
<div
class=
"card text-center h-100"
>
<div
class=
"card-body d-flex flex-column"
>
<h4
class=
"card-title"
>
{{ val.title }}
</h4>
<p
class=
"card-text"
>
{{ val.description }}
</p>
<a
href=
"{{ val.url }}"
class=
"btn btn-primary mt-auto"
target=
"_blank"
>
Voir
<i
class=
"fas fa-external-link-alt ml-1"
></i>
</a>
{% else %}
<div
class=
"col-sm-4 col-md-3 mb-4"
>
<div
class=
"card text-center h-100"
>
<div
class=
"card-body d-flex flex-column"
>
<h4
class=
"card-title"
>
{{ val.title }}
</h4>
<p
class=
"card-text"
>
{{ val.description }}
</p>
<a
href=
"{{ url_for('custom_validator') }}?schema={{val.schema_url|urlencode}}"
class=
"btn btn-primary mt-auto"
>
Choisir
</a
>
</div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
<h2>
Validateur personnalisé
</h2>
<p>
<a
href=
"{{ url_for('custom_validator') }}"
>
Choisissez le schéma qui vous convient
</a
>
<form
action=
"{{ url_for('custom_validator') }}"
method=
"GET"
>
<div
class=
"form-group"
>
<label
for=
"schema"
>
Indiquez l'URL du schema de validation
</label>
<input
name=
"schema"
type=
"url"
class=
"form-control"
id=
"schema"
aria-describedby=
"urlHelp"
placeholder=
"https://..."
/>
</div>
<input
type=
"submit"
value=
"Continuer"
/>
</form>
</p>
{% endblock %}
validata_ui/templates/schema_info_part.html
0 → 100644
View file @
66943441
<h5
class=
"card-title"
>
Schéma
{% if val_info.title %}
« {{ val_info.title }} »
{% else %}
personnalisé
{% endif %}
{#
<span
class=
"badge badge-primary"
>
{{ val_info.version }}
</span>
#}
</h5>
{% if val_info.description %}
<h6
class=
"card-subtitle mb-2 text-muted"
>
{{ val_info.description }}
</h6>
{% endif %}
{% if val_info.author or val_info.contributor %}
<p>
{% if val_info.author %}
Auteur : {{ val_info.author }}
{% endif %}
{% if val_info.contributor %}
<br
/>
Contributeur(s) : {{ val_info.contributor }}
{% endif %}
</p>
{% endif %}
<p>
{% if val_info.doc_url %}
<a
href=
"{{ val_info.doc_url }}"
target=
"_blank"
class=
"card-link"
>
Documentation
</a>
{% else %}
<a
href=
"{{ schema_url }}"
target=
"_blank"
class=
"card-link"
>
{{ schema_url }}
</a>
{% endif %}
</p>
validata_ui/templates/validation_form.html
View file @
66943441
...
...
@@ -2,145 +2,84 @@
block head %}
{{ super() }}
{% endblock %} {% block content %}
<h1
class=
"my-4"
>
Formulaire de validation
</h1>
{#
<h1
class=
"my-4"
>
{{ title }}
</h1>
{% set cols_my_classes = 'my-md-0 my-4' %}
<div
class=
"row"
>
<div
class=
"col-md-4 {{ cols_my_classes }}"
>
<div
class=
"card bg-faded"
>
<div
class=
"card-body"
>
<h5
class=
"card-title"
>
Schéma {{ val_info.code }}
{% if val_info.version %}
<span
class=
"badge badge-primary"
>
{{ val_info.version }}
</span>
{% else %}
<span
class=
"badge badge-primary"
title=
"Schéma en cours de développement"
>
dev
</span
>
{% endif %}
</h5>
<h6
class=
"card-subtitle mb-2 text-muted"
>
{{ val_info.description }}
</h6>
{% if val_info.author or val_info.contributor %}
<p
class=
"text"
>
{% if val_info.author %} Auteur : {{ val_info.author }}
{% endif %} {% if val_info.contributor %}
<br
/>
Contributeur(s) : {{ val_info.contributor }}
{% endif %}
</p>
{% endif %}
</div>
<div
class=
"col-md-4 {{ cols_my_classes }}"
>
<div
class=
"card bg-faded"
>
<div
class=
"card-body"
>
{% include 'schema_info_part.html' %}
</div>
</div>
</div>
</div>
</div>
#}
<div
class=
"col-md-8 {{ cols_my_classes }}"
>
<h2>
Outil de validation
</h2>
<!-- Tab validator -->
<p
class=
"text"
>
Validez ici le fichier de votre choix
</p>
<ul
class=
"nav nav-tabs"
id=
"myTab"
role=
"tablist"
>
<li
class=
"nav-item"
>
<a
class=
"nav-link active"
id=
"file-tab"
data-toggle=
"tab"
href=
"#file"
role=
"tab"
aria-controls=
"file"
aria-selected=
"true"
>
Fichier
</a>
</li>
<li
class=
"nav-item"
>
<a
class=
"nav-link"
id=
"url-tab"
data-toggle=
"tab"
href=
"#url"
role=
"tab"
aria-controls=
"url"
aria-selected=
"false"
>
URL
</a>
</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>
{% set padding_class = 'p-3' %}
<div
class=
"tab-content"
id=
"myTabContent"
>
<div
class=
"tab-pane fade show active {{ padding_class }}"
id=
"file"
role=
"tabpanel"
aria-labelledby=
"file-tab"
>
<form
method=
"POST"
enctype=
"multipart/form-data"
>
<input
type=
"hidden"
name=
"input"
value=
"file"
/>
<input
type=
"hidden"
name=
"schema"
value=
"{{ schema_url }}"
/>
<div
class=
"form-group"
>
<label
for=
"file"
>
Choisissez un fichier tabulaire à valider (.xlsx, .xls, .ods, .csv, .tsv,
etc.)
</label>
<input
type=
"file"
class=
"form-control-file"
name=
"file"
id=
"file"
accept=
".csv, .xls, .xlsx, .ods"
/>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
Valider
</button>
</form>
</div>
<div
class=
"tab-pane fade {{ padding_class }}"
id=
"url"
role=
"tabpanel"
aria-labelledby=
"url-tab"
>
<form
method=
"GET"
>
<input
type=
"hidden"
name=
"input"
value=
"url"
/>
<input
type=
"hidden"
name=
"schema"
value=
"{{ schema_url }}"
/>
<div
class=
"form-group"
>
<label
for=
"url"
>
Indiquez l'URL de la table à valider
</label>
<input
name=
"url"
type=
"url"
class=
"form-control"
id=
"url"
aria-describedby=
"urlHelp"
placeholder=
"https://..."
/>
<div
class=
"row"
>
<div
class=
"col-md-8 {{ cols_my_classes }}"
>
<!-- Tab validator -->
{#
<p
class=
"text"
>
Validez ici le fichier de votre choix
</p>
<ul
class=
"nav nav-tabs"
id=
"myTab"
role=
"tablist"
>
<li
class=
"nav-item"
>
<a
class=
"nav-link active"
id=
"file-tab"
data-toggle=
"tab"
href=
"#file"
role=
"tab"
aria-controls=
"file"
aria-selected=
"true"
>
Fichier
</a
>
</li>
<li
class=
"nav-item"
>
<a
class=
"nav-link"
id=
"url-tab"
data-toggle=
"tab"
href=
"#url"
role=
"tab"
aria-controls=
"url"
aria-selected=
"false"
>
URL
</a
>
</li>
</ul>
{% set padding_class = 'p-3' %}
<div
class=
"tab-content"
id=
"myTabContent"
>
<div
class=
"tab-pane fade show active {{ padding_class }}"
id=
"file"
role=
"tabpanel"
aria-labelledby=
"file-tab"
>
#}
<h2>
Valider un fichier
</h2>
<div>
<form
method=
"POST"
enctype=
"multipart/form-data"
>
<input
type=
"hidden"
name=
"input"
value=
"file"
/>
<div
class=
"form-group"
>
<label
for=
"schema"
>
Indiquez l'URL du schema de validation
</label>
<input
name=
"schema"
type=
"url"
class=
"form-control"
aria-describedby=
"urlHelp"
placeholder=
"https://..."
/>
<div
class=
"form-group"
>
<label
for=
"file"
>
Choisissez un fichier tabulaire à valider (.xlsx, .xls, .ods,
.csv, .tsv, etc.)
</label
>
<input
type=
"file"
class=
"form-control-file"
name=
"file"
id=
"file"
accept=
".csv, .xls, .xlsx, .ods"
/>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
Valider
</button>
</form>
</div>
<h2>
Valider une URL
</h2>
<div
class=
"tab-pane {{ padding_class }}"
id=
"url"
role=
"tabpanel"
aria-labelledby=
"url-tab"
>
<form
method=
"GET"
>
<input
type=
"hidden"
name=
"input"
value=
"url"
/>
<div
class=
"form-group"
>
<label
for=
"schema"
>
Indiquez l'URL du schema de validation
</label>
<input
name=
"schema"
type=
"url"
class=
"form-control"
id=
"schema"
aria-describedby=
"urlHelp"
placeholder=
"https://..."
/>
<div
class=
"form-group"
>
<label
for=
"url"
>
Indiquez l'URL de la table à valider
</label>
<input
name=
"url"
type=
"url"
class=
"form-control"
id=
"url"
aria-describedby=
"urlHelp"
placeholder=
"https://..."
/>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
Valider
</button>
</form>
</div>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
Valider
</button>
</form>
</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>
{% endblock %} {% block footer %} {% endblock %}
validata_ui/templates/validation_report.html
View file @
66943441
...
...
@@ -45,25 +45,8 @@
<div
class=
"row"
>
<div
class=
"col-md-{% if print_mode %}12{% else %}5{% endif %} my-4"
>
<div
class=
"card bg-faded"
>
<div
class=
"card-body"
>
<h5
class=
"card-title"
>
Schéma
<span
class=
"badge badge-primary"
>
{{ val_info.version }}
</span>
</h5>
<h6
class=
"card-subtitle mb-2 text-muted"
>
{{ val_info.description }}
</h6>
{% if val_info.author or val_info.contributor %}
<p>
{% if val_info.author %}
Auteur : {{ val_info.author }}
{% endif %}
{% if val_info.contributor %}
<br
/>
Contributeur(s) : {{ val_info.contributor }}
{% endif %}
</p>
{% endif %}
<p>
<a
href=
"{{ schema_url }}"
target=
"_blank"
class=
"card-link"
>
{{ schema_url }}
</a>
</p>
<div
class=
"card-body"
>
{% include 'schema_info_part.html' %}
<hr
/>
<div>
<h5
class=
"card-title"
>
...
...
validata_ui/views.py
View file @
66943441
...
...
@@ -22,7 +22,7 @@ from validata_core.loaders import custom_loaders
import
tabulator
from
.
import
app
,
config
from
.
import
app
,
config
,
ui_config
,
schema_info_map
from
.ui_util
import
flash_error
,
flash_warning
from
.validata_util
import
ValidataSource
...
...
@@ -298,8 +298,10 @@ def validate(schema_url, source: ValidataSource):
validata_report
=
create_validata_ui_report
(
validata_core_report
,
schema_dict
)
# Display report to the user
validator_form_url
=
url_for
(
"custom_validator"
)
+
'?schema='
+
quote_plus
(
schema_url
)
val_info
,
validator_title
=
compute_validator_info
(
schema_url
)
return
render_template
(
'validation_report.html'
,
title
=
'Rapport de validation'
,
val_info
=
{}
,
report
=
validata_report
,
val_info
=
val_info
,
report
=
validata_report
,
schema_url
=
schema_url
,
validation_date
=
report_datetime
.
strftime
(
'le %d/%m/%Y à %Hh%M'
),
source
=
source
,
source_type
=
source
.
type
,
source_data
=
source_data
,
...
...
@@ -307,7 +309,7 @@ def validate(schema_url, source: ValidataSource):
badge_url
=
badge_url
,
badge_msg
=
badge_msg
,
report_str
=
json
.
dumps
(
validata_report
,
sort_keys
=
True
,
indent
=
2
),
breadcrumbs
=
[{
'url'
:
url_for
(
'home'
),
'title'
:
'Accueil'
},
{
'url'
:
url_for
(
'custom_validator'
),
'title'
:
'Schéma personnalisé'
},
{
'url'
:
validator_form_url
,
'title'
:
validator_title
},
])
...
...
@@ -325,25 +327,8 @@ def bytes_data(f):
@
app
.
route
(
'/'
)
def
home
():
""" Home page """
external_validators
=
[
{
"title"
:
"INSPIRE"
,
"description"
:
"proposé par la Commission Européenne pour tester des ressources géographiques (données, services ou métadonnées)"
,
"url"
:
"http://inspire-sandbox.jrc.ec.europa.eu/validator/"
},
{
"title"
:
"BAL"
,
"description"
:
"proposé par la mission Etalab pour tester des données Adresse produites localement (format BAL 1.1)"
,
"url"
:
"https://adresse.data.gouv.fr/bases-locales/validateur"
},
{
"title"
:
"CVDTC"
,
"description"
:
"proposé par l'AFIMB dans le cadre du projet Chouette pour tester des données de transport collectif (GTFS ou NEPTUNE)"
,
"url"
:
"http://www.conversion-validation-donnees-tc.org/"
},
]
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
=
[],
external_validators
=
external_validators
)
return
render_template
(
'home.html'
,
title
=
'Accueil'
,
config
=
ui_config
)
@
app
.
route
(
'/validators'
)
...
...
@@ -394,6 +379,16 @@ def pdf_report():
return
response
def
compute_validator_info
(
schema_url
):
"""Factor code for validator form page"""
val_info
=
None
title
=
"Schéma personnalisé"
if
schema_url
in
schema_info_map
:
val_info
=
schema_info_map
.
get
(
schema_url
)
title
=
"Schéma « {} »"
.
format
(
val_info
[
'title'
])
return
val_info
,
title
@
app
.
route
(
'/validators/form'
,
methods
=
[
'GET'
,
'POST'
])
def
custom_validator
():
""" Validator page """
...
...
@@ -402,54 +397,61 @@ def custom_validator():
flash_error
(
"URL de connexion à l'API non indiquée :-("
)
return
redirect
(
url_for
(
'home'
))
def
validation_form_url
(
schema_url
):
"""Computes validation form url with schema URL parameter"""
return
"{}?schema={}"
.
format
(
url_for
(
'custom_validator'
),
quote_plus
(
schema_url
))
if
request
.
method
==
'GET'
:
input_param
=
request
.
args
.
get
(
'input'
)
url_param
=
request
.
args
.
get
(
"url"
)
schema_param
=
request
.
args
.
get
(
"schema"
)
if
schema_param
is
None
or
schema_param
==
''
:
flash_error
(
"Vous n'avez pas indiqué d'url de schéma"
)
return
redirect
(
url_for
(
'home'
))
# First form display
if
input_param
is
None
:
return
render_template
(
'validation_form.html'
,
title
=
"Formulaire de validation"
,
val_info
=
None
,
val_info
,
title
=
compute_validator_info
(
schema_param
)
return
render_template
(
'validation_form.html'
,
title
=
title
,
val_info
=
val_info
,
schema_url
=
schema_param
,
breadcrumbs
=
[{
'url'
:
url_for
(
'home'
),
'title'
:
'Accueil'
},
])
# Process URL
else
:
if
url_param
is
None
or
url_param
==
''
:
flash_error
(
"Vous n'avez pas indiqué d'url à valider"
)
return
redirect
(
url_for
(
'custom_validator'
))
if
schema_param
is
None
or
schema_param
==
''
:
flash_error
(
"Vous n'avez pas indiqué d'url de schéma"
)
return
redirect
(
url_for
(
'custom_validator'
))
return
redirect
(
validation_form_url
(
schema_param
))
try
:
return
validate
(
schema_param
,
ValidataSource
(
'url'
,
url_param
,
url_param
))
except
tabulator
.
exceptions
.
FormatError
as
e
:
flash_error
(
'Erreur : Format de ressource non supporté'
)
log
.
info
(
e
)
return
redirect
(
url_for
(
'custom_validator'
))
return
redirect
(
validation_form_url
(
schema_param
))
except
tabulator
.
exceptions
.
HTTPError
as
e
:
flash_error
(
'Erreur : impossible d
\'
accéder au fichier source en ligne'
)
log
.
info
(
e
)
return
redirect
(
url_for
(
'custom_validator'
))
return
redirect
(
validation_form_url
(
schema_param
))
else
:
# POST
input_param
=
request
.
form
.
get
(
'input'
)
if
input_param
is
None
:
flash_error
(
'Aucun fichier à valider'
)
return
redirect
(
url_for
(
'custom_validator'
))
schema_param
=
request
.
form
.
get
(
'schema'
)
if
schema_param
is
None
:
flash_error
(
'Aucun schéma défini'
)
return
redirect
(
url_for
(
'custom_validator'
))
return
redirect
(
url_for
(
'home'
))