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
|
#!/usr/bin/python
import web
import controller
import model
#
# URL Mappings
#
urls = (
"/add/?", controller.Add,
"/edit/(\d+)", controller.Edit,
"/const/?", controller.Const,
"/const/(\d+)", controller.Const,
"/const/add/?", controller.ConstAdd,
"/const/add/from/(\d+)", controller.ConstAdd,
"/const/edit/(\d+)", controller.ConstEdit,
"/categories", controller.Cat,
"/(\d\d\d\d)/(\d\d?)/?", controller.Show,
"/", controller.Show,
"/(.*)", controller.FourOhFour
)
#
# ORM
#
def handle_sql(handler):
web.ctx.orm = model.Session()
try:
try:
h = handler()
except web.HTTPError:
web.ctx.orm.commit()
raise
except:
web.ctx.orm.rollback()
raise
else:
web.ctx.orm.commit()
return h
finally:
model.Session.remove()
#
# Check for mobile (at least somewhat)
#
mobile_checks = ["J2ME", "Opera Mini"]
def handle_mobile():
ua = web.ctx.env.get("HTTP_USER_AGENT", "")
web.ctx.is_mobile = any((x in ua) for x in mobile_checks)
#
# The App
#
app = web.application(urls, globals())
app.notfound = controller.FourOhFour.catch
# add processors
app.add_processor(handle_sql)
app.add_processor(web.loadhook(handle_mobile))
# debug for the moment
web.config.debug = True
#
# And go!
if __name__ == "__main__":
app.run()
|