| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 | 2 |
| 3 # This Source Code is subject to the terms of the Mozilla Public License | 3 # This file is part of the Adblock Plus web scripts, |
| 4 # version 2.0 (the "License"). You can obtain a copy of the License at | 4 # Copyright (C) 2006-2012 Eyeo GmbH |
| 5 # http://mozilla.org/MPL/2.0/. | 5 # |
| 6 # Adblock Plus is free software: you can redistribute it and/or modify | |
| 7 # it under the terms of the GNU General Public License version 3 as | |
| 8 # published by the Free Software Foundation. | |
| 9 # | |
| 10 # Adblock Plus is distributed in the hope that it will be useful, | |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 # GNU General Public License for more details. | |
| 14 # | |
| 15 # You should have received a copy of the GNU General Public License | |
| 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
| 6 | 17 |
| 7 import re | 18 import re |
| 8 from urlparse import parse_qs | 19 from urlparse import parse_qs |
| 9 from sitescripts.reports.utils import getUser, getUserUsefulnessScore | 20 from sitescripts.reports.utils import getUser, getReportsForUser |
| 10 from sitescripts.utils import get_config, get_template, setupStderr | 21 from sitescripts.utils import get_config, get_template, setupStderr |
| 11 from sitescripts.web import url_handler | 22 from sitescripts.web import url_handler |
| 12 | 23 |
| 13 @url_handler('/showUser') | 24 @url_handler('/showUser') |
| 14 def handleRequest(environ, start_response): | 25 def handleRequest(environ, start_response): |
| 15 setupStderr(environ['wsgi.errors']) | 26 setupStderr(environ['wsgi.errors']) |
| 16 | 27 |
| 17 params = parse_qs(environ.get('QUERY_STRING', '')) | 28 params = parse_qs(environ.get('QUERY_STRING', '')) |
| 18 | 29 |
| 19 id = params.get('id', [''])[0].lower() | 30 id = params.get('id', [''])[0].lower() |
| 20 if not re.match(r'^[\da-f]{32}$', id): | 31 if not re.match(r'^[\da-f]{32}$', id): |
| 21 return showError('Invalid or missing ID', start_response) | 32 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 | 33 |
| 24 user = getUser(id) | 34 user = getUser(id) |
| 25 if user == None: | 35 if user == None: |
| 26 return showError('User not found', start_response) | 36 return showError('User not found', start_response) |
| 27 | 37 |
| 28 user['score'] = getUserUsefulnessScore(id) | 38 user['reportlist'] = getReportsForUser(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 | 39 |
| 30 template = get_template(get_config().get('reports', 'showUserTemplate')) | 40 template = get_template(get_config().get('reports', 'showUserTemplate')) |
| 31 start_response('200 OK', [('Content-Type', 'application/xhtml+xml; charset=utf -8')]) | 41 start_response('200 OK', [('Content-Type', 'application/xhtml+xml; charset=utf -8')]) |
| 32 return [template.render(user).encode('utf-8')] | 42 return [template.render(user).encode('utf-8')] |
| 33 | 43 |
| 34 def showError(message, start_response): | 44 def showError(message, start_response): |
| 35 template = get_template(get_config().get('reports', 'errorTemplate')) | 45 template = get_template(get_config().get('reports', 'errorTemplate')) |
| 36 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm l; charset=utf-8')]) | 46 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm l; charset=utf-8')]) |
| 37 return [template.render({'message': message}).encode('utf-8')] | 47 return [template.render({'message': message}).encode('utf-8')] |
| LEFT | RIGHT |