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 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 | 4 # version 2.0 (the "License"). You can obtain a copy of the License at |
5 # http://mozilla.org/MPL/2.0/. | 5 # http://mozilla.org/MPL/2.0/. |
6 | 6 |
7 import re, os, sys, random | 7 import re, os, sys, random |
8 from urlparse import parse_qsl | 8 from urlparse import parse_qsl |
9 from sitescripts.utils import get_config, get_template, setupStderr | 9 from sitescripts.utils import get_config, get_template, setupStderr |
10 from sitescripts.web import url_handler | 10 from sitescripts.web import url_handler |
11 from sitescripts.reports.utils import calculateReportSecret, calculateReportSecr et_compat, getReport, saveReport, sendUpdateNotification | 11 from sitescripts.reports.utils import calculateReportSecret, calculateReportSecr et_compat, getReport, saveReport, sendUpdateNotification, getUserId, updateUserU sefulness |
12 | 12 |
13 @url_handler('/updateReport') | 13 @url_handler('/updateReport') |
14 def handleRequest(environ, start_response): | 14 def handleRequest(environ, start_response): |
15 setupStderr(environ['wsgi.errors']) | 15 setupStderr(environ['wsgi.errors']) |
16 | 16 |
17 if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYP E', '').startswith('application/x-www-form-urlencoded'): | 17 if environ['REQUEST_METHOD'].upper() != 'POST' or not environ.get('CONTENT_TYP E', '').startswith('application/x-www-form-urlencoded'): |
18 return showError('Unsupported request method', start_response) | 18 return showError('Unsupported request method', start_response) |
19 | 19 |
20 try: | 20 try: |
21 request_body_length = int(environ['CONTENT_LENGTH']) | 21 request_body_length = int(environ['CONTENT_LENGTH']) |
(...skipping 15 matching lines...) Expand all Loading... | |
37 return showError('Report does not exist', start_response) | 37 return showError('Report does not exist', start_response) |
38 | 38 |
39 secret = calculateReportSecret(guid) | 39 secret = calculateReportSecret(guid) |
40 if params.get('secret', '') != secret and params.get('secret', '') != calculat eReportSecret_compat(guid): | 40 if params.get('secret', '') != secret and params.get('secret', '') != calculat eReportSecret_compat(guid): |
41 return showError('Wrong secret value', start_response) | 41 return showError('Wrong secret value', start_response) |
42 | 42 |
43 reportData['status'] = params.get('status', '') | 43 reportData['status'] = params.get('status', '') |
44 if len(reportData['status']) > 1024: | 44 if len(reportData['status']) > 1024: |
45 reportData['status'] = reportData['status'][:1024] | 45 reportData['status'] = reportData['status'][:1024] |
46 | 46 |
47 if (reportData.get('email', None)): | 47 oldusefulness = reportData['usefulness'] |
48 reportData['utility'] = params.get('utility', 0) | 48 reportData['usefulness'] = params.get('usefulness', '0') |
Wladimir Palant
2012/10/18 15:41:24
Isn't this value a string? The default value shoul
Andrey Novikov
2012/10/18 15:51:29
Done.
| |
49 if ('email' in reportData): | |
50 updateUserUsefulness(getUserId(reportData['email']), reportData['usefulness' ], oldusefulness) | |
49 | 51 |
50 saveReport(guid, reportData) | 52 saveReport(guid, reportData) |
51 | 53 |
52 if params.get('notify', '') and 'email' in reportData: | 54 if params.get('notify', '') and 'email' in reportData: |
53 email = reportData['email'] | 55 email = reportData['email'] |
54 email = re.sub(r' at ', r'@', email) | 56 email = re.sub(r' at ', r'@', email) |
55 email = re.sub(r' dot ', r'.', email) | 57 email = re.sub(r' dot ', r'.', email) |
56 if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email): | 58 if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email): |
57 sendUpdateNotification({ | 59 sendUpdateNotification({ |
58 'email': email, | 60 'email': email, |
59 'url': get_config().get('reports', 'urlRoot') + guid, | 61 'url': get_config().get('reports', 'urlRoot') + guid, |
60 'status': reportData['status'], | 62 'status': reportData['status'], |
61 }) | 63 }) |
62 | 64 |
63 newURL = get_config().get('reports', 'urlRoot') + guid | 65 newURL = get_config().get('reports', 'urlRoot') + guid |
64 newURL += '?updated=' + str(int(random.uniform(0, 10000))) | 66 newURL += '?updated=' + str(int(random.uniform(0, 10000))) |
65 newURL += '#secret=' + secret | 67 newURL += '#secret=' + secret |
66 start_response('302 Found', [('Location', newURL.encode('utf-8'))]) | 68 start_response('302 Found', [('Location', newURL.encode('utf-8'))]) |
67 return [] | 69 return [] |
68 | 70 |
69 def showError(message, start_response): | 71 def showError(message, start_response): |
70 template = get_template(get_config().get('reports', 'errorTemplate')) | 72 template = get_template(get_config().get('reports', 'errorTemplate')) |
71 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm l; charset=utf-8')]) | 73 start_response('400 Processing Error', [('Content-Type', 'application/xhtml+xm l; charset=utf-8')]) |
72 return [template.render({'message': message}).encode('utf-8')] | 74 return [template.render({'message': message}).encode('utf-8')] |
LEFT | RIGHT |