-
Notifications
You must be signed in to change notification settings - Fork 1
/
todo.py
60 lines (42 loc) · 1.16 KB
/
todo.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
""" Basic todo list using webpy 0.3 """
import os
import web
import model
### Url mappings
urls = (
'/', 'Index',
'/del/(\d+)', 'Delete'
)
### Templates
render = web.template.render('templates', base='base')
class Index:
form = web.form.Form(
web.form.Textbox('title', web.form.notnull,
description="I need to:"),
web.form.Button('Add todo'),
)
def GET(self):
""" Show page """
todos = model.get_todos()
form = self.form()
return render.index(todos, form)
def POST(self):
""" Add new entry """
form = self.form()
if not form.validates():
todos = model.get_todos()
return render.index(todos, form)
model.new_todo(form.d.title)
raise web.seeother('/')
class Delete:
def POST(self, id):
""" Delete based on ID """
id = int(id)
model.del_todo(id)
raise web.seeother('/')
app = web.application(urls, globals())
### if __name__ == '__main__':
### app.run()
port = os.getenv('VCAP_APP_PORT', '8080')
if __name__ == '__main__':
web.httpserver.runsimple(app.wsgifunc(),("0.0.0.0",int(port)))