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

Delta Between Two Patch Sets: sitescripts/reports/web/updateReport.py

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

Powered by Google App Engine
This is Rietveld