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

Side by Side Diff: sitescripts/reports/utils.py

Issue 8617068: Reports - user stats update (Closed)
Patch Set: Created Oct. 18, 2012, 2:27 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 | « no previous file | no next file » | 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 hashlib, hmac, base64, MySQLdb, os, re, marshal, subprocess 7 import hashlib, hmac, base64, MySQLdb, os, re, marshal, subprocess
8 from sitescripts.utils import get_config, cached, get_template, sendMail 8 from sitescripts.utils import get_config, cached, get_template, sendMail
9 9
10 def getReportSubscriptions(guid): 10 def getReportSubscriptions(guid):
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 reportData['guid'] = guid 93 reportData['guid'] = guid
94 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html') 94 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html')
95 dir = os.path.dirname(file) 95 dir = os.path.dirname(file)
96 if not os.path.exists(dir): 96 if not os.path.exists(dir):
97 os.makedirs(dir) 97 os.makedirs(dir)
98 template = get_template(get_config().get('reports', 'webTemplate')) 98 template = get_template(get_config().get('reports', 'webTemplate'))
99 template.stream(reportData).dump(file, encoding='utf-8') 99 template.stream(reportData).dump(file, encoding='utf-8')
100 100
101 def removeReport(guid): 101 def removeReport(guid):
102 reportData = getReport(guid)
103 if (reportData.get('email', None)):
104 utility = reportData['utility']
105 contact = getUserId(reportData['email'])
106 updateUserUtility(contact, utility)
Wladimir Palant 2012/10/18 15:45:52 So you are updating user's score only after 30 day
107
102 cursor = get_db().cursor() 108 cursor = get_db().cursor()
103 executeQuery(cursor, 109 executeQuery(cursor,
104 '''DELETE FROM #PFX#reports WHERE guid = %s''', 110 '''DELETE FROM #PFX#reports WHERE guid = %s''',
105 (guid)) 111 (guid))
106 get_db().commit() 112 get_db().commit()
107 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html') 113 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html')
108 if os.path.isfile(file): 114 if os.path.isfile(file):
109 os.remove(file) 115 os.remove(file)
110 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.png') 116 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.png')
111 if os.path.isfile(file): 117 if os.path.isfile(file):
112 os.remove(file) 118 os.remove(file)
113 119
120 def updateUserUtility(contact, utility):
121 if utility == 0:
122 return
123 cursor = get_db().cursor()
124 if utility > 0:
125 executeQuery(cursor,
126 '''UPDATE #PFX#users SET positive = positive + 1 WHERE id = %s'' ',
127 (contact))
128 else:
129 executeQuery(cursor,
130 '''UPDATE #PFX#users SET negative = negative + 1 WHERE id = %s'' ',
131 (contact))
132 get_db().commit()
133
114 def saveScreenshot(guid, screenshot): 134 def saveScreenshot(guid, screenshot):
115 prefix = 'data:image/png;base64,' 135 prefix = 'data:image/png;base64,'
116 if not screenshot.startswith(prefix): 136 if not screenshot.startswith(prefix):
117 raise TypeError('Screenshot is not a PNG image') 137 raise TypeError('Screenshot is not a PNG image')
118 data = base64.b64decode(screenshot[len(prefix):]) 138 data = base64.b64decode(screenshot[len(prefix):])
119 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.png') 139 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.png')
120 dir = os.path.dirname(file) 140 dir = os.path.dirname(file)
121 if not os.path.exists(dir): 141 if not os.path.exists(dir):
122 os.makedirs(dir) 142 os.makedirs(dir)
123 f = open(file, 'wb') 143 f = open(file, 'wb')
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 dbpasswd = get_config().get('reports', 'dbpassword') 195 dbpasswd = get_config().get('reports', 'dbpassword')
176 if os.name == 'nt': 196 if os.name == 'nt':
177 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8', named_pipe=True) 197 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8', named_pipe=True)
178 else: 198 else:
179 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8') 199 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8')
180 200
181 def executeQuery(cursor, query, args=None): 201 def executeQuery(cursor, query, args=None):
182 tablePrefix = get_config().get('reports', 'dbprefix') 202 tablePrefix = get_config().get('reports', 'dbprefix')
183 query = re.sub(r'#PFX#', tablePrefix, query) 203 query = re.sub(r'#PFX#', tablePrefix, query)
184 cursor.execute(query, args) 204 cursor.execute(query, args)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld