Permalink
Browse files

Better export users script

  • Loading branch information...
1 parent ecf8074 commit 275eebd4b20d780e5d0a8e7d6a730b8e7a277475 @kumar303 kumar303 committed Mar 5, 2012
Showing with 8 additions and 14 deletions.
  1. +8 −14 adhoc/export_users.py
View
@@ -12,26 +12,20 @@ def main():
connection = sqlite.connect(chirp_db)
cursor = connection.cursor()
-
cursor.execute("select * from auth_user where is_active=1")
-
users = cursor.fetchall()
- ## sqlite
- #0:id,1:username,2:first_name,3:last_name
- #4:email,5:password,6:is_staff,7:is_active,8:is_superuser
- #9:last_login,10:date_joined
-
- ## To model:
- # email:4,first_name:2,last_name:3,password,is_active:7,is_superuser:8
- # last_login:9 (ignored) ,date_joined:10,roles
-
users_file = open('users.csv', 'w')
writer = csv.writer(users_file)
+ fields = [d[0] for d in cursor.description]
for user in users:
- email = user[4]
- # empty password so that reset is forced after import:
- writer.writerow([email,user[2],user[3], '', user[7],user[8],user[10].split('.')[0], 'dj'])
+ data = dict(zip(fields, user))
+ if not data['email']:
+ raise ValueError('active DJs cannot have empty emails: %s' % data)
+ writer.writerow([data['email'], data['first_name'], data['last_name'],
+ # empty password so that reset is forced after import:
+ '', data['is_active'], data['is_superuser'],
+ data['date_joined'].split('.')[0], 'dj'])
cursor.close()
connection.close()

0 comments on commit 275eebd

Please sign in to comment.