Commit 62c085e8 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Delete unused

parent e39000b5
#!/usr/bin/env python3
Validata-ui-next entry-point
import json
import os
from collections import OrderedDict
from pathlib import Path
from flask import Flask, flash, redirect, render_template, request, url_for
app = Flask(__name__)
app.secret_key = 'MyPr3ci0u5$€cr€t'
schemas_config = {
"scdl-prenoms": {
"schema_json_url": "",
"custom_checks_json_url": ""}
VALIDATOR_JSON_FILE = 'static/data/scdl-validators.json'
class Validators:
validator_map = OrderedDict()
def init(cls, validators_file):
""" Static init """
val_list = json.load(open(validators_file))
cls.validator_map = OrderedDict([(val['code'], val) for val in val_list])
def list(cls):
""" Validator list """
return [val for _, val in cls.validator_map.items()]
def is_valid_code(cls, code):
""" Test if validator code exist """
return code in cls.validator_map
def is_val_enabled(cls, val):
ret = val and val.get('enable', 'true') == 'true'
return ret
def info(cls, code):
""" Return information on validator """
return cls.validator_map.get(code)
# TODO externalize util classes
def validate_url(url):
return "TODO: valider l'url "+url
# return render_template('validation_report.html')
def validate_file(file):
return "TODO: valider le fichier "+file
# return render_template('validation_report.html')
def flash_error(msg):
flash(msg, 'danger')
def flash_warning(msg):
flash(msg, 'warning')
def flash_success(msg):
flash(msg, 'success')
def flash_info(msg):
flash(msg, 'info')
def home():
validators = [{**val, 'enabled': Validators.is_val_enabled(val)} for val in Validators.list()]
return render_template('home.html', title='Accueil', validators=validators)
def about():
return render_template('about.html', title='À propos',
breadcrumbs=[{'url': url_for('home'), 'title': 'Accueil'}, ])
def validators():
return redirect(url_for('home'))
@app.route('/validators/<val_code>', methods=['GET', 'POST'])
def scdl_validator(val_code):
if not Validators.is_valid_code(val_code):
flash_error('Validateur [{}] inconnu'.format(val_code))
return redirect(url_for('home'))
if not Validators.is_val_enabled(
flash_error('Pas de validateur pour le schéma [{}]'.format(val_code))
return redirect(url_for('home'))
if request.method == 'GET':
val_info =
input_param = request.args.get('input')
# First form display
if input_param is None or input_param not in ('url', 'example'):
return render_template('validator.html', title=val_info['name'],
breadcrumbs=[{'url': url_for('home'), 'title': 'Accueil'}, ])
# Process URL
url = request.args.get('url')
if url is None or url == '':
flash_error("Vous n'avez pas indiqué d'url à valider")
return redirect(url_for('scdl_validator', val_code=val_code))
return validate_url(url)
else: # POST
input_param = request.form.get('input')
if input_param is None:
flash_error('Source non définie')
return redirect(url_for('scdl_validator', val_code=val_code))
# File validation
if input_param == 'file':
f = request.files.get('file')
if f is None:
flash_warning("Vous n'avez pas indiqué de fichier à valider")
return redirect(url_for('scdl_validator', val_code=val_code))'/tmp', f.filename))
return validate_file(f.filename)
return 'Bizarre, vous avez dit bizarre ?'
if __name__ == '__main__':
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