webfront.py

Wed, 24 Jan 2018 23:14:01 +0200

author
Santeri Piippo
date
Wed, 24 Jan 2018 23:14:01 +0200
changeset 31
02e7e1d73ebb
parent 29
db6ca177c6c4
child 32
75f44d3063da
permissions
-rw-r--r--

Fix math domain errors in vector_angle

from flask import Flask, render_template, redirect, request
from ldcheck import load_config, load_colours, find_ldconfig_ldr_paths
from ldcheck import read_ldraw
from testsuite import load_tests, check_model, format_report_html

app = Flask('LDCheck')

@app.route('/', methods = ['GET', 'POST'])
def web_front():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files or not request.files['file'].filename:
            return redirect(request.url)
        file = request.files['file']
        print(type(file))
        config = load_config('ldcheck.cfg')
        for ldconfig_ldr_path in find_ldconfig_ldr_paths(config):
            with ldconfig_ldr_path.open() as ldconfig_ldr:
                load_colours(ldconfig_ldr)
        model = read_ldraw(
            file.stream,
            name = file.filename,
            config = config,
        )
        test_suite = load_tests()
        report = check_model(model, test_suite)
        return str.format(
            '<!doctype html><html><body><ul>{report}</ul></body></html>',
            report = format_report_html(report, model, test_suite)
        )
    return '''
    <!doctype html>
    <title>Upload new File</title>
    <h1>Upload new File</h1>
    <form method=post enctype=multipart/form-data>
      <p><input type=file name=file>
         <input type=submit value=Upload>
    </form>
    '''

app.run()

mercurial