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

wip

parent af1a8f31
......@@ -6,3 +6,6 @@ SECRET_KEY="dev"
# Comment the two following lines to disable "badge" generation.
BADGE_CONFIG_URL="https://git.opendatafrance.net/validata/validata-badge/raw/master/badge_conf.toml"
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
Non-breaking changes:
......
......@@ -5,15 +5,17 @@ from urllib.parse import quote_plus
import flask
import jinja2
import validata_core
#import validata_core
# Let this import after app initialisation
from . import config
from .validate_helper import ValidatorHelper
#from .validate_helper import ValidatorHelper
# Schemas settings
schemas_config = validata_core.get_schemas_config()
ValidatorHelper.init(schemas_config)
# schemas_config = validata_core.get_schemas_config()
# ValidatorHelper.init(schemas_config)
# TODO: load config.toml
# Flask things
app = flask.Flask(__name__)
......
......@@ -12,6 +12,9 @@ load_dotenv()
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 = 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" %}
{% block title %}{{ title }}{% endblock %}
{% block head %}
{% extends "base_template.html" %} {% block title %}{{ title }}{% endblock %} {%
block head %}
{{ super() }}
{% endblock %}
{% block content %}
{% 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>
<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>
</div>
</div>
{% 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
>
</div>
</div>
{% endfor %}
</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>
</div>
</div>
{% 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>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endblock %}
\ No newline at end of file
<h2>Validateur personnalisé</h2>
<p>
<a href="{{ url_for('custom_validator') }}"
>Choisissez le schéma qui vous convient</a
>
</p>
{% endblock %}
......@@ -3,10 +3,8 @@
import logging
from io import BytesIO
import validata_core
from validata_core.source_helpers import build_tabulator_params
from .validate_helper import ValidatorHelper
log = logging.getLogger(__name__)
......@@ -14,9 +12,9 @@ log = logging.getLogger(__name__)
class ValidataSource():
""" Handy class to handle different sort of data source """
def __init__(self, type, name, source):
def __init__(self, type_, name, source):
""" Initialization """
self.type = type
self.type = type_
self.name = name
self.source = source
......@@ -25,10 +23,17 @@ class ValidataSource():
self.format = info.get('format')
self.scheme = info.get('scheme')
def get_tabulator_params(self):
""" Creates source ready to be ingested by tabulator """
def is_url(self):
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):
......
......@@ -61,9 +61,6 @@ class ValidatorHelper:
return [cls.schema_info(code) for code in sorted(cls.schema_dict.keys())]
@classmethod
def validate(cls, schema_code, **options):
""" Try to retrieve cached schema from `schema_code`, otherwise pass `schema_code` it as-is """
schema = cls.schema(schema_code)
if schema is None:
schema = schema_code
return cls.validator.validate(schema=schema, **options)
def validate(cls, schema_url, **options):
"""Validate"""
return cls.validator.validate(schema=schema_url, **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