Skip to content

Instantly share code, notes, and snippets.

@acarmisc
Created June 4, 2013 19:52
Show Gist options
  • Save acarmisc/5708980 to your computer and use it in GitHub Desktop.
Save acarmisc/5708980 to your computer and use it in GitHub Desktop.
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