Created
June 4, 2013 19:52
-
-
Save acarmisc/5708980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Products.CMFCore.utils import getToolByName | |
users = context['users.csv'].data.split('\n') | |
regtool = getToolByName(context, 'portal_registration') | |
index = 1 | |
imported_count = 0 | |
for user in users: | |
tokens = user.split(';') | |
if len(tokens) == 5: | |
passwd, id, last, first, email = tokens | |
properties = { | |
'username' : id, | |
'fullname' : '%s %s' % (first, last), | |
'email' : email.strip(), | |
} | |
try: | |
regtool.addMember(id, passwd, properties=properties) | |
print "Successfully added %s %s (%s) with email %s" % (first, last, id, email) | |
imported_count += 1 | |
except ValueError, e: | |
print "Couldn't add %s: %s" % (id, e) | |
else: | |
print "Could not parse line %d because it had the following contents: '%s'" % (index, user) | |
index += 1 | |
print "Imported %d users (from %d lines of CSV)" % (imported_count, index) | |
return printed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment