Changeset 2751
- Timestamp:
- 11/07/07 15:49:15 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
flexibleassigntoplugin/0.11/trunk/flexibleassignto/flexibleassignto.py
r2665 r2751 13 13 ## python imports 14 14 from pprint import pprint, pformat 15 import psycopg2 #import IntegrityError 15 16 16 17 ## trac imports … … 208 209 return _tag 209 210 211 def _get_allusers_session_info(self, cnx): 212 """ 213 """ 214 cursor = cnx.cursor() 215 cursor.execute(''' 216 SELECT DISTINCT n.sid AS sid, n.value AS name, e.value AS email 217 FROM session_attribute AS n 218 LEFT JOIN session_attribute AS e ON (e.sid=n.sid 219 AND e.authenticated=1 AND e.name = 'email') 220 WHERE n.authenticated=1 221 AND n.name = 'name' 222 ORDER BY n.sid''') 223 for username,name,email in cursor: 224 yield username, name, email 225 210 226 def _ensure_user_data(self, users): 211 227 """ … … 214 230 values for 'name' or 'email'. 215 231 """ 216 EMAIL_SQL = '''INSERT OR IGNOREINTO session_attribute232 EMAIL_SQL = '''INSERT INTO session_attribute 217 233 (sid, authenticated, name, value) 218 VALUES ( "%s", 1, "email" , "%s")'''219 NAME_SQL = '''INSERT OR IGNOREINTO session_attribute234 VALUES ('%s', 1, 'email' , '%s')''' 235 NAME_SQL = '''INSERT INTO session_attribute 220 236 (sid, authenticated, name, value) 221 VALUES ( "%s", 1, "name" , "%s")'''237 VALUES ('%s', 1, 'name' , '%s')''' 222 238 db = self.env.get_db_cnx() 223 239 cursor = db.cursor() 240 known_users = self._get_allusers_session_info(db) 241 known_usernames = [u[0] for u in known_users] 224 242 for u in users: 225 243 _username = str(u.getUsername()).strip() 226 244 _email = str(u.email).strip() 227 245 _fullname = str(u.fullname).strip() 228 if u.getUsername() and _username != '': 246 if u.getUsername() and _username != '' and \ 247 _username not in known_usernames: 229 248 if u.email and _email != '': 230 cursor.execute(EMAIL_SQL % (_username, _email)) 249 try: 250 cursor.execute(EMAIL_SQL % (_username, _email)) 251 except psycopg2.IntegrityError: 252 pass 231 253 if u.fullname and _fullname != '': 232 cursor.execute(NAME_SQL % (_username, _fullname)) 233 db.commit() 254 try: 255 cursor.execute(NAME_SQL % (_username, _fullname)) 256 except psycopg2.IntegrityError: 257 pass 258 #db.commit() 234 259 cursor.close() 235 260
