webfront.py

changeset 29
db6ca177c6c4
child 32
75f44d3063da
equal deleted inserted replaced
28:5933250813a3 29:db6ca177c6c4
1 from flask import Flask, render_template, redirect, request
2 from ldcheck import load_config, load_colours, find_ldconfig_ldr_paths
3 from ldcheck import read_ldraw
4 from testsuite import load_tests, check_model, format_report_html
5
6 app = Flask('LDCheck')
7
8 @app.route('/', methods = ['GET', 'POST'])
9 def web_front():
10 if request.method == 'POST':
11 # check if the post request has the file part
12 if 'file' not in request.files or not request.files['file'].filename:
13 return redirect(request.url)
14 file = request.files['file']
15 print(type(file))
16 config = load_config('ldcheck.cfg')
17 for ldconfig_ldr_path in find_ldconfig_ldr_paths(config):
18 with ldconfig_ldr_path.open() as ldconfig_ldr:
19 load_colours(ldconfig_ldr)
20 model = read_ldraw(
21 file.stream,
22 name = file.filename,
23 config = config,
24 )
25 test_suite = load_tests()
26 report = check_model(model, test_suite)
27 return str.format(
28 '<!doctype html><html><body><ul>{report}</ul></body></html>',
29 report = format_report_html(report, model, test_suite)
30 )
31 return '''
32 <!doctype html>
33 <title>Upload new File</title>
34 <h1>Upload new File</h1>
35 <form method=post enctype=multipart/form-data>
36 <p><input type=file name=file>
37 <input type=submit value=Upload>
38 </form>
39 '''
40
41 app.run()

mercurial