Index: sitescripts/reports/web/showUser.py |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/sitescripts/reports/web/showUser.py |
@@ -0,0 +1,37 @@ |
+# coding: utf-8 |
+ |
+# This Source Code is subject to the terms of the Mozilla Public License |
+# version 2.0 (the "License"). You can obtain a copy of the License at |
+# http://mozilla.org/MPL/2.0/. |
+ |
+import re |
+from urlparse import parse_qs |
+from sitescripts.reports.utils import getUser, getUserUsefulnessScore |
+from sitescripts.utils import get_config, get_template, setupStderr |
+from sitescripts.web import url_handler |
+ |
+@url_handler('/showUser') |
+def handleRequest(environ, start_response): |
+ setupStderr(environ['wsgi.errors']) |
+ |
+ params = parse_qs(environ.get('QUERY_STRING', '')) |
+ |
+ id = params.get('id', [''])[0].lower() |
+ if not re.match(r'^[\da-f]{32}$', id): |
+ return showError('Invalid or missing ID', start_response) |
+ 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.
|
+ |
+ user = getUser(id) |
+ if user == None: |
+ return showError('User not found', start_response) |
+ |
+ 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.
|
+ |
+ template = get_template(get_config().get('reports', 'showUserTemplate')) |
+ start_response('200 OK', [('Content-Type', 'application/xhtml+xml; charset=utf-8')]) |
+ return [template.render(user).encode('utf-8')] |
+ |
+def showError(message, start_response): |
+ template = get_template(get_config().get('reports', 'errorTemplate')) |
+ start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xml; charset=utf-8')]) |
+ return [template.render({'message': message}).encode('utf-8')] |