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

Delta Between Two Patch Sets: sitescripts/reports/utils.py

Issue 8793015: Reports - user profile (Closed)
Left Patch Set: Created Nov. 6, 2012, 2:05 p.m.
Right Patch Set: Reports - user profile Created Nov. 7, 2012, 11:39 a.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/template/showUser.html ('k') | sitescripts/reports/web/showUser.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 file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2012 Eyeo GmbH 4 # Copyright (C) 2006-2012 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 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 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 28 matching lines...) Expand all
39 comment, hasscreenshot, knownissues 39 comment, hasscreenshot, knownissues
40 FROM #PFX#reports WHERE ctime >= FROM_UNIXTIME(%s) LIMIT %s OFFS ET %s''', 40 FROM #PFX#reports WHERE ctime >= FROM_UNIXTIME(%s) LIMIT %s OFFS ET %s''',
41 (startTime, count, offset)) 41 (startTime, count, offset))
42 rows = cursor.fetchall() 42 rows = cursor.fetchall()
43 cursor.close() 43 cursor.close()
44 if len(rows) == 0: 44 if len(rows) == 0:
45 break 45 break
46 for row in rows: 46 for row in rows:
47 yield row 47 yield row
48 offset += len(rows) 48 offset += len(rows)
49
50 def getReportsForUser(contact):
51 cursor = get_db().cursor(MySQLdb.cursors.DictCursor)
52 executeQuery(cursor,
53 '''SELECT guid, type, UNIX_TIMESTAMP(ctime) AS ctime, status, site , contact,
54 comment, hasscreenshot, knownissues
55 FROM #PFX#reports WHERE contact = %s ORDER BY ctime DESC LIMIT 100 ''',
56 (contact))
57 rows = cursor.fetchall()
58 cursor.close()
59 return rows
49 60
50 def getReport(guid): 61 def getReport(guid):
51 cursor = get_db().cursor() 62 cursor = get_db().cursor()
52 executeQuery(cursor, 63 executeQuery(cursor,
53 '''SELECT dump FROM #PFX#reports WHERE guid = %s''', 64 '''SELECT dump FROM #PFX#reports WHERE guid = %s''',
54 (guid)) 65 (guid))
55 report = cursor.fetchone() 66 report = cursor.fetchone()
56 if report == None: 67 if report == None:
57 return None 68 return None
58 69
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if id != None: 106 if id != None:
96 filterMatch = lambda f: any(u == sn['id'] for u in f.get('subscriptions' , [])) 107 filterMatch = lambda f: any(u == sn['id'] for u in f.get('subscriptions' , []))
97 hasMatches = any(filterMatch(f) for f in reportData.get('filters', [])) 108 hasMatches = any(filterMatch(f) for f in reportData.get('filters', []))
98 executeQuery(cursor, 109 executeQuery(cursor,
99 '''INSERT IGNORE INTO #PFX#sublists (report, list, hasmatches) VA LUES (%s, %s, %s)''', 110 '''INSERT IGNORE INTO #PFX#sublists (report, list, hasmatches) VA LUES (%s, %s, %s)''',
100 (guid, id[0], hasMatches)) 111 (guid, id[0], hasMatches))
101 112
102 get_db().commit() 113 get_db().commit()
103 114
104 reportData['guid'] = guid 115 reportData['guid'] = guid
105 if contact: 116 if contact:
Wladimir Palant 2012/11/07 08:38:15 What if there is an email field but no contact? Th
Andrey Novikov 2012/11/07 09:38:48 Few lines above we have: contact = getUserId(repor
106 email = reportData['email'] 117 email = reportData['email']
107 email = re.sub(r' at ', r'@', email) 118 email = re.sub(r' at ', r'@', email)
108 email = re.sub(r' dot ', r'.', email) 119 email = re.sub(r' dot ', r'.', email)
109 reportData['email'] = anonymizeMail(email) 120 reportData['email'] = anonymizeMail(email)
110 reportData['uid'] = contact 121 reportData['uid'] = contact
111 122
112 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html') 123 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html')
113 dir = os.path.dirname(file) 124 dir = os.path.dirname(file)
114 if not os.path.exists(dir): 125 if not os.path.exists(dir):
115 os.makedirs(dir) 126 os.makedirs(dir)
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 dbpasswd = get_config().get('reports', 'dbpassword') 254 dbpasswd = get_config().get('reports', 'dbpassword')
244 if os.name == 'nt': 255 if os.name == 'nt':
245 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8', named_pipe=True) 256 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8', named_pipe=True)
246 else: 257 else:
247 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8') 258 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8')
248 259
249 def executeQuery(cursor, query, args=None): 260 def executeQuery(cursor, query, args=None):
250 tablePrefix = get_config().get('reports', 'dbprefix') 261 tablePrefix = get_config().get('reports', 'dbprefix')
251 query = re.sub(r'#PFX#', tablePrefix, query) 262 query = re.sub(r'#PFX#', tablePrefix, query)
252 cursor.execute(query, args) 263 cursor.execute(query, args)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld