-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
46 lines (35 loc) · 1.41 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from bottle import route, run, template, request, redirect, static_file, get
import time
import validate
import os
@get('/<filename:re:.*\.css>')
def stylesheets(filename):
return static_file(filename, root='static/css')
@route('/')
def main(message=None):
return template('main.tpl', message=message)
@route('/goback', method='POST')
def gotomain():
return redirect('/')
@route('/upload', method='POST')
def do_upload():
upload = request.files.get('upload')
name, ext = os.path.splitext(upload.filename)
filename = _generate_filename(name, ext)
upload.save(filename)
xsd = validate.xsd_from_file('23_2014_szamlasema.xsd')
xml = validate.xml_from_file(filename)
os.remove(filename)
if xsd is None:
return template('main.tpl', message="Something went wrong processing the scheme definition.")
elif xml is None:
return template('main.tpl', message="Something went wrong processing the XML file. Are you sure it is in correct format?")
errors = _check_for_errors(xml, xsd)
return template('result.tpl', errors=errors)
def _generate_filename(name, ext):
timestamp = time.strftime("%Y%m%d%H%M%S")
return f'{name}_{timestamp}{ext}'
def _check_for_errors(xml, xsd):
error_log = validate.validate_with_errors(xml, xsd)
return validate.xsd_error_log_as_simple_strings(error_log[1])
run(host='0.0.0.0', port=8080, debug=True)