Commit 84c0a3a8 authored by Pierre Dittgen's avatar Pierre Dittgen

wip

parent af1a8f31
...@@ -6,3 +6,6 @@ SECRET_KEY="dev" ...@@ -6,3 +6,6 @@ SECRET_KEY="dev"
# Comment the two following lines to disable "badge" generation. # Comment the two following lines to disable "badge" generation.
BADGE_CONFIG_URL="https://git.opendatafrance.net/validata/validata-badge/raw/master/badge_conf.toml" BADGE_CONFIG_URL="https://git.opendatafrance.net/validata/validata-badge/raw/master/badge_conf.toml"
SHIELDS_IO_BASE_URL="https://img.shields.io/" 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
## 0.1.0 -> next
Non-breaking changes:
- New feature: validate a CSV against a schema URL
- UI now depends on validata-api, no more on validata-core
## 0.0.1 -> 0.1.0 ## 0.0.1 -> 0.1.0
Non-breaking changes: Non-breaking changes:
......
...@@ -5,15 +5,17 @@ from urllib.parse import quote_plus ...@@ -5,15 +5,17 @@ from urllib.parse import quote_plus
import flask import flask
import jinja2 import jinja2
import validata_core #import validata_core
# Let this import after app initialisation # Let this import after app initialisation
from . import config from . import config
from .validate_helper import ValidatorHelper #from .validate_helper import ValidatorHelper
# Schemas settings # Schemas settings
schemas_config = validata_core.get_schemas_config() # schemas_config = validata_core.get_schemas_config()
ValidatorHelper.init(schemas_config) # ValidatorHelper.init(schemas_config)
# TODO: load config.toml
# Flask things # Flask things
app = flask.Flask(__name__) app = flask.Flask(__name__)
......
...@@ -12,6 +12,9 @@ load_dotenv() ...@@ -12,6 +12,9 @@ load_dotenv()
SECRET_KEY = os.environ.get("SECRET_KEY") or None SECRET_KEY = os.environ.get("SECRET_KEY") or None
API_VALIDATE_ENDPOINT = os.environ.get("API_VALIDATE_ENDPOINT") or None
if API_VALIDATE_ENDPOINT is None:
log.error("API_VALIDATE_ENDPOINT environment variable is not set, validation is not possible")
BADGE_CONFIG_URL = os.environ.get("BADGE_CONFIG_URL") or None BADGE_CONFIG_URL = os.environ.get("BADGE_CONFIG_URL") or None
BADGE_CONFIG = None BADGE_CONFIG = None
......
{% extends "base_template.html" %} {% block title %}{{ title }}{% endblock %} {%
block head %}
{{ super() }}
{% endblock %} {% block content %}
<h1 class="my-4">Validateur personnalisé</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>
</div>
</div>
#}
<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>
</div>
</div>
{% endblock %} {% block footer %} {% endblock %}
{% extends "base_template.html" %} {% extends "base_template.html" %} {% block title %}{{ title }}{% endblock %} {%
{% block title %}{{ title }}{% endblock %} block head %}
{% block head %}
{{ super() }} {{ super() }}
{% endblock %} {% endblock %} {% block content %}
{% block content %}
<h1 class="my-4">Validez vos jeux de données</h1> <h1 class="my-4">Validez vos jeux de données</h1>
<h2>Validateurs <span abbr="Socle commun des données locales">SCDL</span></h2> <h2>Validateurs <span abbr="Socle commun des données locales">SCDL</span></h2>
<div class="row my-4"> <div class="row my-4">
{% for val in validators %} {% for val in validators %}
<div class="col-sm-4 col-md-3 mb-4"> <div class="col-sm-4 col-md-3 mb-4">
<div class="card text-center h-100"> <div class="card text-center h-100">
<div class="card-body d-flex flex-column"> <div class="card-body d-flex flex-column">
<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 href="{{ url_for('scdl_validator', val_code=val.code) }}" class="btn btn-primary mt-auto">Choisir</a> <a
</div> href="{{ url_for('scdl_validator', val_code=val.code) }}"
</div> class="btn btn-primary mt-auto"
>Choisir</a
>
</div>
</div> </div>
{% endfor %} </div>
{% endfor %}
</div> </div>
<h2>Validateurs externes</h2> <h2>Validateurs externes</h2>
<div class="row my-4"> <div class="row my-4">
{% for val in external_validators %} {% for val in external_validators %}
<div class="col-sm-4 col-md-3 mb-4"> <div class="col-sm-4 col-md-3 mb-4">
<div class="card text-center h-100"> <div class="card text-center h-100">
<div class="card-body d-flex flex-column"> <div class="card-body d-flex flex-column">
<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 href="{{ val.url }}" class="btn btn-primary mt-auto" target="_blank"> <a href="{{ val.url }}" class="btn btn-primary mt-auto" target="_blank">
Voir Voir
<i class="fas fa-external-link-alt ml-1"></i> <i class="fas fa-external-link-alt ml-1"></i>
</a> </a>
</div> </div>
</div>
</div> </div>
{% endfor %} </div>
{% endfor %}
</div> </div>
{% endblock %} <h2>Validateur personnalisé</h2>
\ No newline at end of file <p>
<a href="{{ url_for('custom_validator') }}"
>Choisissez le schéma qui vous convient</a
>
</p>
{% endblock %}
...@@ -3,10 +3,8 @@ ...@@ -3,10 +3,8 @@
import logging import logging
from io import BytesIO from io import BytesIO
import validata_core
from validata_core.source_helpers import build_tabulator_params from validata_core.source_helpers import build_tabulator_params
from .validate_helper import ValidatorHelper
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -14,9 +12,9 @@ log = logging.getLogger(__name__) ...@@ -14,9 +12,9 @@ log = logging.getLogger(__name__)
class ValidataSource(): class ValidataSource():
""" Handy class to handle different sort of data source """ """ Handy class to handle different sort of data source """
def __init__(self, type, name, source): def __init__(self, type_, name, source):
""" Initialization """ """ Initialization """
self.type = type self.type = type_
self.name = name self.name = name
self.source = source self.source = source
...@@ -25,10 +23,17 @@ class ValidataSource(): ...@@ -25,10 +23,17 @@ class ValidataSource():
self.format = info.get('format') self.format = info.get('format')
self.scheme = info.get('scheme') self.scheme = info.get('scheme')
def get_tabulator_params(self): def is_url(self):
""" Creates source ready to be ingested by tabulator """ return self.type == 'url'
return {'source': self.source, 'format': self.format, 'scheme': self.scheme} def get_url(self):
return self.source
def get_filename(self):
return self.name
def get_filecontent(self):
return self.source
def bytes_data(f): def bytes_data(f):
......
...@@ -61,9 +61,6 @@ class ValidatorHelper: ...@@ -61,9 +61,6 @@ class ValidatorHelper:
return [cls.schema_info(code) for code in sorted(cls.schema_dict.keys())] return [cls.schema_info(code) for code in sorted(cls.schema_dict.keys())]
@classmethod @classmethod
def validate(cls, schema_code, **options): def validate(cls, schema_url, **options):
""" Try to retrieve cached schema from `schema_code`, otherwise pass `schema_code` it as-is """ """Validate"""
schema = cls.schema(schema_code) return cls.validator.validate(schema=schema_url, **options)
if schema is None:
schema = schema_code
return cls.validator.validate(schema=schema, **options)
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