Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/reports/web/updateReport.py

Issue 8625042: Reports - user usefullness (Closed)
Patch Set: Reports - user usefulness Created Oct. 29, 2012, 12:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/reports/utils.py ('k') | sitescripts/utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 oldusefulness = reportData['usefulness']
48 reportData['usefulness'] = params.get('usefulness', '0')
49 if ('email' in reportData):
50 updateUserUsefulness(getUserId(reportData['email']), reportData['usefulness' ], oldusefulness)
51
47 saveReport(guid, reportData) 52 saveReport(guid, reportData)
48 53
49 if params.get('notify', '') and 'email' in reportData: 54 if params.get('notify', '') and 'email' in reportData:
50 email = reportData['email'] 55 email = reportData['email']
51 email = re.sub(r' at ', r'@', email) 56 email = re.sub(r' at ', r'@', email)
52 email = re.sub(r' dot ', r'.', email) 57 email = re.sub(r' dot ', r'.', email)
53 if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email): 58 if re.match(r'^[\w.%+-]+@[\w.%+-]+(\.[\w.%+-]+)+', email):
54 sendUpdateNotification({ 59 sendUpdateNotification({
55 'email': email, 60 'email': email,
56 'url': get_config().get('reports', 'urlRoot') + guid, 61 'url': get_config().get('reports', 'urlRoot') + guid,
57 'status': reportData['status'], 62 'status': reportData['status'],
58 }) 63 })
59 64
60 newURL = get_config().get('reports', 'urlRoot') + guid 65 newURL = get_config().get('reports', 'urlRoot') + guid
61 newURL += '?updated=' + str(int(random.uniform(0, 10000))) 66 newURL += '?updated=' + str(int(random.uniform(0, 10000)))
62 newURL += '#secret=' + secret 67 newURL += '#secret=' + secret
63 start_response('302 Found', [('Location', newURL.encode('utf-8'))]) 68 start_response('302 Found', [('Location', newURL.encode('utf-8'))])
64 return [] 69 return []
65 70
66 def showError(message, start_response): 71 def showError(message, start_response):
67 template = get_template(get_config().get('reports', 'errorTemplate')) 72 template = get_template(get_config().get('reports', 'errorTemplate'))
68 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')])
69 return [template.render({'message': message}).encode('utf-8')] 74 return [template.render({'message': message}).encode('utf-8')]
OLDNEW
« no previous file with comments | « sitescripts/reports/utils.py ('k') | sitescripts/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld