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

Delete unused app.py

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": "https://git.openqqq.com/",
"custom_checks_json_url": ""}
}
VALIDATOR_JSON_FILE = 'static/data/scdl-validators.json'
class Validators:
validator_map = OrderedDict()
@classmethod
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])
@classmethod
def list(cls):
""" Validator list """
return [val for _, val in cls.validator_map.items()]
@classmethod
def is_valid_code(cls, code):
""" Test if validator code exist """
return code in cls.validator_map
@classmethod
def is_val_enabled(cls, val):
ret = val and val.get('enable', 'true') == 'true'
return ret
@classmethod
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')
Validators.init(VALIDATOR_JSON_FILE)
@app.route('/')
def home():
validators = [{**val, 'enabled': Validators.is_val_enabled(val)} for val in Validators.list()]
return render_template('home.html', title='Accueil', validators=validators)
@app.route('/about')
def about():
return render_template('about.html', title='À propos',
breadcrumbs=[{'url': url_for('home'), 'title': 'Accueil'}, ])
@app.route('/validators')
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(Validators.info(val_code)):
flash_error('Pas de validateur pour le schéma [{}]'.format(val_code))
return redirect(url_for('home'))
if request.method == 'GET':
val_info = Validators.info(val_code)
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'],
val_info=val_info,
breadcrumbs=[{'url': url_for('home'), 'title': 'Accueil'}, ])
# Process URL
else:
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))
f.save(os.path.join('/tmp', f.filename))
return validate_file(f.filename)
return 'Bizarre, vous avez dit bizarre ?'
if __name__ == '__main__':
app.run()
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