Personal tools
You are here: Home Documentation How To's Mass or batch user create

Mass or batch user create

by Nguyen, T. Kim last modified Jun 22, 2012 04:23 PM

Add many users to your Plone site with one file and one script

As inspired by http://plone.org/documentation/kb/batch-adding-users

 

The format I used is simpler:

Kim Nguyen <nguyen@uwosh.edu>
Joe The Shark <joetheshark@uwosh.edu>

 

 

The script I used:

# Create new members with properties supplied from a CSV file.
# The script expects a File object with id `users.csv` in the same folder
# it resides.
#
# The format of the CSV needs to be:
#
# name;email
#
# created 2006-11-03 by Tom Lazar <tom@tomster.org>, http://tomster.org/
# under a BSD-style licence (i.e. use as you wish but don't sue me)

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:
    user = user.strip('>')
    tokens = user.split('<')
    if len(tokens) == 2:
        name, email = tokens
        properties = {
            'username' : email,
            'fullname' : name,
            'email' : email.strip(),
        }
        try:
            passwd = regtool.generatePassword()
            regtool.addMember(email, passwd, properties=properties)
            print "Successfully added %s (%s) with email %s" % (name, email, email)
            imported_count += 1
        except ValueError, e:
            print "Couldn't add %s: %s" % (email, 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
 

 

Document Actions
  • Print this
  • Bookmarks