diff options
Diffstat (limited to 'clepyweb/registration.py')
-rw-r--r-- | clepyweb/registration.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/clepyweb/registration.py b/clepyweb/registration.py new file mode 100644 index 0000000..cb2f80d --- /dev/null +++ b/clepyweb/registration.py | |||
@@ -0,0 +1,55 @@ | |||
1 | import logging | ||
2 | |||
3 | import urlrelay | ||
4 | from webob import Request, Response | ||
5 | |||
6 | from mako.lookup import TemplateLookup | ||
7 | |||
8 | lookup = TemplateLookup(directories=['templates',]) | ||
9 | |||
10 | logging.basicConfig(filename='registrations.log', level=logging.CRITICAL) | ||
11 | |||
12 | @urlrelay.url('^/$', 'GET') | ||
13 | def index(environ, start_response): | ||
14 | res = Response() | ||
15 | |||
16 | template = lookup.get_template('index.html') | ||
17 | |||
18 | res.body = template.render() | ||
19 | |||
20 | return res(environ, start_response) | ||
21 | |||
22 | @urlrelay.url('^/$', 'POST') | ||
23 | def register(environ, start_response): | ||
24 | req = Request(environ) | ||
25 | |||
26 | name = req.params.get('name') | ||
27 | email = req.params.get('email') | ||
28 | food = req.params.get('food') | ||
29 | |||
30 | logging.critical('Name: {0}, Email: {1}, Food: {2}'.format(name, email, food)) | ||
31 | |||
32 | res = Response() | ||
33 | |||
34 | res.status = '302 Found' | ||
35 | res.headers['Location'] = '/thankyou?name={0}&email={1}&food={2}'.format(name, email, food) | ||
36 | |||
37 | return res(environ, start_response) | ||
38 | |||
39 | @urlrelay.url('^/thankyou$', 'GET') | ||
40 | def thankyou(environ, start_response): | ||
41 | req = Request(environ) | ||
42 | |||
43 | name = req.params.get('name') | ||
44 | email = req.params.get('email') | ||
45 | food = req.params.get('food') | ||
46 | |||
47 | res = Response() | ||
48 | |||
49 | template = lookup.get_template('thankyou.html') | ||
50 | |||
51 | res.body = template.render(name=name, email=email, food=food) | ||
52 | |||
53 | return res(environ, start_response) | ||
54 | |||
55 | \ No newline at end of file | ||