-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.py
63 lines (41 loc) · 1.16 KB
/
web.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
# coding: utf8
import DB
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def read():
my_notes = []
for n, note in enumerate(DB.open_file()):
if len(note):
my_notes.append((n, note))
return render_template('index.html', notes=my_notes)
@app.route('/write')
def write():
return render_template('write.html')
@app.route('/write_get')
def write_get():
val = request.args.get('note', 'пустая заметка')
DB.write_file(val)
return val
@app.route('/change')
def change():
notes = []
for n, note in enumerate(DB.open_file()):
if len(note):
notes.append((n, note))
return render_template('change.html', notes=notes)
@app.route('/write_post', methods=['POST'])
def write_post():
val = request.form['note']
DB.write_file(val)
return val
@app.route('/operation/<select>/<int:n>', methods=['GET', 'POST'])
def edit(select, n):
if select == 'edit':
val = request.form['note']
DB.edit(val, n)
elif select == 'delete':
DB.remove_element(n)
return 'ok'
if __name__ == '__main__':
app.run(debug=True)