webfront.py

changeset 63
8949af6a4279
parent 62
f0a6bf48b05e
child 65
f2dc17b830e0
child 99
01941a811b5a
equal deleted inserted replaced
62:f0a6bf48b05e 63:8949af6a4279
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 from flask import Flask, render_template, redirect, request 2 from flask import Flask, render_template, redirect, request
3 from ldcheck import load_config, load_colours, find_ldconfig_ldr_paths 3 from ldcheck import load_config, load_colours, find_ldconfig_ldr_paths
4 from parse import read_ldraw 4 from parse import read_ldraw
5 from testsuite import load_tests, check_model, problem_text 5 from testsuite import load_tests, check_model, problem_text, all_problem_types
6 6
7 app = Flask('LDCheck') 7 app = Flask('LDCheck')
8 8
9 @app.route('/', methods = ['GET', 'POST']) 9 @app.route('/', methods = ['GET', 'POST'])
10 def web_front(): 10 def web_front():
11 test_suite = load_tests()
11 if request.method == 'POST': 12 if request.method == 'POST':
12 # check if the post request has the file part 13 # check if the post request has the file part
13 if 'file' not in request.files or not request.files['file'].filename: 14 if 'file' not in request.files or not request.files['file'].filename:
14 return redirect(request.url) 15 return redirect(request.url)
15 file = request.files['file'] 16 file = request.files['file']
21 model = read_ldraw( 22 model = read_ldraw(
22 file.stream, 23 file.stream,
23 name = filename, 24 name = filename,
24 ldraw_directories = config['libraries'], 25 ldraw_directories = config['libraries'],
25 ) 26 )
26 test_suite = load_tests()
27 report = check_model(model, test_suite) 27 report = check_model(model, test_suite)
28 28
29 # Amend human-readable messages into the report 29 # Amend human-readable messages into the report
30 for problem in report['problems']: 30 for problem in report['problems']:
31 object = model.body[problem.body_index] 31 object = model.body[problem.body_index]
32 problem.message_str = problem_text(problem, test_suite) 32 problem.message_str = problem_text(problem, test_suite)
33 problem.ldraw_code = object.textual_representation() 33 problem.ldraw_code = object.textual_representation()
34 return render_template('webfront.html',
35 report = report,
36 name = filename,
37 problem_types = all_problem_types(test_suite)
38 )
34 else: 39 else:
35 report = None 40 test_suite = load_tests()
36 filename = None 41 return render_template('webfront.html',
37 return render_template('webfront.html', 42 report = None,
38 report = report, 43 name = None,
39 name = filename 44 problem_types = all_problem_types(test_suite)
40 ) 45 )
41 46
42 @app.route('/static/<path:path>') 47 @app.route('/static/<path:path>')
43 def static_file(path): 48 def static_file(path):
44 from flask import send_from_directory 49 from flask import send_from_directory
45 from os import path 50 from os import path

mercurial