forked from ceprio/editablegrid-python-sqlite-example
/
main.py
94 lines (82 loc) · 2.41 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#
# This file is base on EditableGrid example.
# http://editablegrid.net
#
# Copyright 2018 by ceprio
# This file is part of editablegrid-python-sqlite-example which is released under the MIT License.
# See file LICENCE_1 or go to https://github.com/ceprio/editablegrid-python-sqlite-example for
# full license details.
from flask import Flask, render_template, request, json, redirect
app = Flask(__name__)
app.debug = True
_base_path = '/editablegrid'
@app.route(_base_path+'/css/<path:path>')
def css_files(path):
return app.send_static_file('css/' + path)
@app.route(_base_path+'/js/<path:path>')
def js_files(path):
return app.send_static_file('js/' + path)
@app.route('/')
def hello():
return redirect(_base_path+"/", code=302)
@app.route(_base_path+'/', methods=['GET'])
def index():
plot_svg = ''
plot_code = ''
if 'style' in request.args:
form_defaults = dict(request.args) # get all current entries from form
plot_code = PlotHandler.BuildPlotCode(form_defaults)
glo = {'ret':''}
exec(plot_code, glo)
plot_svg = glo['ret']
else:
form_defaults = {}
print('first')
return render_template('index.html', form_defaults=form_defaults)
@app.route(_base_path+'/loaddata.py', methods=['GET'])
def _loaddata():
import loaddata
data = loaddata.main(request.args)
# with open("data.json", "w") as file:
# file.write(data)
response = app.response_class(
response=data,
status=200,
mimetype='application/json'
)
return response
@app.route(_base_path+'/add.py', methods=['POST'])
def _add():
import add
data = add.main(request.form)
response = app.response_class(
response=data,
status=200,
mimetype='text/plain'
)
return response
@app.route(_base_path+'/update.py', methods=['POST'])
def _update():
import update
data = update.main(request.values)
response = app.response_class(
response=data,
status=200,
mimetype='text/plain'
)
return response
@app.route(_base_path+'/delete.py', methods=['POST'])
def _delete():
print("delete")
import delete
data = delete.main(request.values)
response = app.response_class(
response=data,
status=200,
mimetype='text/plain'
)
return response
if __name__ == "__main__":
app.run()