]>
Commit | Line | Data |
---|---|---|
e4fd5e1b | 1 | import mitsql |
a30bf1b7 | 2 | |
e4fd5e1b | 3 | import cherrypy |
a30bf1b7 | 4 | mako = cherrypy.tools.mako |
e4fd5e1b JP |
5 | |
6 | from pprint import pformat | |
7 | ||
a30bf1b7 JP |
8 | #def _500(*argv, **kw): |
9 | # s_exc = cherrypy._cperror.format_exc() | |
10 | # mitsql.logging.error(s_exc) | |
11 | # return templates.common.shell(title='%s (CherryPy %s)' % (kw.get('status'), kw.get('version')), | |
12 | # content=('<p>%s</p>' + (2*'<div><pre>%s</pre></div>')) | |
13 | # % (kw.get('message'), kw.get('traceback'), | |
14 | # _phtml(dict(filter(lambda x: not x[0][:2] == '__', | |
15 | # cherrypy.request.__dict__.items()))))) | |
16 | ||
17 | def _before_request_body(): | |
18 | if not cherrypy.request.login is None: | |
19 | if cherrypy.request.login.endswith('@MIT.EDU'): | |
20 | cherrypy.request.login = cherrypy.request.login[:-8] | |
21 | else: | |
22 | cherrypy.request.login = None | |
23 | ||
24 | from databases import mysql, pgsql | |
e4fd5e1b JP |
25 | |
26 | class Root(object): | |
a30bf1b7 JP |
27 | _cp_config = { |
28 | 'hooks.before_request_body': _before_request_body, | |
29 | 'tools.mako.collection_size': 500, | |
30 | 'tools.mako.directories': mitsql._base+'/www/templates', | |
31 | } | |
32 | #class Error(object): | |
33 | # def _404(*argv, **kw): | |
34 | # return templates.common._404() | |
35 | # def _500(*argv, **kw): | |
36 | # return _500(*argv, **kw) | |
37 | #error = Error() | |
e4fd5e1b | 38 | |
a30bf1b7 | 39 | @cherrypy.expose |
e4fd5e1b JP |
40 | def test(self, *argv, **kw): |
41 | cherrypy.response.headers['Content-type'] = 'text/plain' | |
42 | return pformat(dict(filter(lambda x: not x[0][:2] == '__', cherrypy.request.__dict__.items()))) | |
e4fd5e1b | 43 | |
a30bf1b7 JP |
44 | @cherrypy.expose |
45 | @mako(filename='index') | |
e4fd5e1b | 46 | def index(self, *argv, **kw): |
a30bf1b7 JP |
47 | return { |
48 | 'title': 'SQL Service', | |
49 | 'login': cherrypy.request.login, | |
50 | } | |
e4fd5e1b | 51 | |
a30bf1b7 JP |
52 | @cherrypy.expose |
53 | @mako(filename='passwd') | |
e4fd5e1b | 54 | def passwd(self, *argv, **kw): |
a30bf1b7 JP |
55 | return { |
56 | 'title': 'Change Passwords', | |
57 | 'login': cherrypy.request.login, | |
58 | } | |
59 | ||
60 | @cherrypy.expose | |
61 | @mako(filename='contact') | |
62 | def contact(self, *argv, **kw): | |
63 | return { | |
64 | 'title': 'Contact', | |
65 | } | |
66 | ||
67 | @cherrypy.expose | |
68 | @mako(filename='database') | |
69 | def database(self, *argv, **kw): | |
70 | return { | |
71 | 'title': 'Databases', | |
72 | 'login': cherrypy.request.login, | |
73 | 'mysql': mysql.list(cherrypy.request.login), | |
74 | 'pgsql': pgsql.list(cherrypy.request.login), | |
75 | } | |
76 | ||
77 | #Root._cp_config['error_page.404'] = Root.error._404 | |
78 | #Root._cp_config['error_page.500'] = Root.error._500 |