Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 # coding: utf-8 | |
2 | |
3 # This Source Code is subject to the terms of the Mozilla Public License | |
4 # version 2.0 (the "License"). You can obtain a copy of the License at | |
5 # http://mozilla.org/MPL/2.0/. | |
6 | |
7 import re | |
8 from urlparse import parse_qs | |
9 from sitescripts.reports.utils import getUser, getUserUsefulnessScore | |
10 from sitescripts.utils import get_config, get_template, setupStderr | |
11 from sitescripts.web import url_handler | |
12 | |
13 @url_handler('/showUser') | |
14 def handleRequest(environ, start_response): | |
15 setupStderr(environ['wsgi.errors']) | |
16 | |
17 params = parse_qs(environ.get('QUERY_STRING', '')) | |
18 | |
19 id = params.get('id', [''])[0].lower() | |
20 if not re.match(r'^[\da-f]{32}$', id): | |
21 return showError('Invalid or missing ID', start_response) | |
22 email = params.get('email', [''])[0].lower() | |
Wladimir Palant
2012/11/07 08:38:15
Left-over code? Please remove.
Andrey Novikov
2012/11/07 09:38:48
Done.
| |
23 | |
24 user = getUser(id) | |
25 if user == None: | |
26 return showError('User not found', start_response) | |
27 | |
28 user['score'] = getUserUsefulnessScore(id) | |
Wladimir Palant
2012/11/07 08:38:15
You know that I dislike doing two database queries
Andrey Novikov
2012/11/07 09:38:48
Done.
| |
29 | |
30 template = get_template(get_config().get('reports', 'showUserTemplate')) | |
31 start_response('200 OK', [('Content-Type', 'application/xhtml+xml; charset=utf -8')]) | |
32 return [template.render(user).encode('utf-8')] | |
33 | |
34 def showError(message, start_response): | |
35 template = get_template(get_config().get('reports', 'errorTemplate')) | |
36 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm l; charset=utf-8')]) | |
37 return [template.render({'message': message}).encode('utf-8')] | |
OLD | NEW |