-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (55 loc) · 2.29 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
from flask import Flask, request
import flask
import pyvibe as pv
import pycob as cob
import uuid
import pandas as pd
app = Flask(__name__)
@app.route('/')
def index():
page = pv.Page('Home')
with page.add_card() as card:
card.add_header('Enter some data')
with card.add_form(action="/save", method="POST") as form:
form.add_formtext(label="Name", name="name", placeholder="Enter your name")
form.add_formtextarea(label="Message", name="message", placeholder="Enter your message")
form.add_formsubmit(label="Save")
return page.to_html()
@app.route('/save', methods=['POST'])
def save():
name = flask.request.form.get('name')
message = flask.request.form.get('message')
id = uuid.uuid4().hex
cob.store_dict('messages', id, {'id': id, 'name': name, 'message': message})
page = pv.Page('Saved')
page.add_header('Your message has been saved')
page.add_text('PyVibe is used for illustration purposes. You can use any HTML templating engine you like.')
page.add_code('import pycob as cob', header="Import pycob")
page.add_code('''cob.store_dict('messages', uuid.uuid4().hex, {'name': name, 'message': message})''', header="Store dictionary")
page.add_link('View messages', '/list')
return page.to_html()
@app.route('/list')
def list():
messages = cob.list_objects('messages')
page = pv.Page('Messages')
page.add_header('Messages')
page.add_code('import pycob as cob', header="Import pycob")
page.add_code('''messages = cob.list_objects('messages')''', header="List objects")
action_buttons = [
pv.Rowaction(label='Delete', url='/delete?id={id}', open_in_new_window=False)
]
page.add_pandastable(pd.DataFrame(messages), action_buttons=action_buttons)
page.add_link('Add message', '/')
return page.to_html()
@app.route('/delete')
def delete():
id = flask.request.args.get('id')
cob.delete_dict('messages', id)
page = pv.Page('Deleted')
page.add_header('Your message has been deleted')
page.add_code('import pycob as cob', header="Import pycob")
page.add_code('''cob.delete_dict('messages', id)''', header="Delete dictionary")
page.add_link('View messages', '/list')
return page.to_html()
if __name__ == '__main__':
app.run(debug=True)