Personal tools
You are here: Home Documentation How-tos Batch-adding Users to Plone using CSV (Excel) files
Support

Get Help

Join our chat rooms or support forums if you have more specific questions.

Plone Training
Learn how to design, build, and deploy a website in Plone through one of the numerous Plone training sessions around the world.
Find Plone training…
 
Document Actions

Batch-adding Users to Plone using CSV (Excel) files

This How-to applies to: Plone 2.5.x
This How-to is intended for: Site Administrators

How to import/create new users from CSV- a.k.a. Excel-files
  1. Create a textfile with your userdata. The format is:
    password;userid;lastname;firstname;email
  2. Log into the ZMI of your site and create a 'File' instance at the root of your plone instance. Give it the id 'users.csv' and the file you just created:

  3. Download this script.
  4. Also at the site root, create a 'Script (Python') instance in the root folder of your plone instance with the id 'importPASfromCSV' and the script you just downloaded. Click the 'Add and Edit' button:

  5. In the following form click on the 'Test' tab:

    This will execute the script and its output will be shown onscreen.
  6. There is no step 6.
from tomster.org
Attached files
by Tom Lazar last modified November 4, 2006 - 00:59 All content is copyright Plone Foundation and the individual contributors.

Exception

Posted by Arthur Albano at November 9, 2006 - 22:00
I had to use the string method strip() on the last token (in the source, email, line 25), so it increased compatibility. Yhanks for the script. Saved me a lot of time!

Line 25:
'emai': email,

to

'email': email.strip()

Exception

Posted by Arthur Albano at November 9, 2006 - 22:00
I had to use the string method strip() on the last token (in the source, email, line 25), so it increased compatibility. Thanks for the script. Saved me a lot of time!

Line 25:
'emai': email,

to

'email': email.strip()

seems reasonable

Posted by Tom Lazar at March 1, 2007 - 21:17
that seems like a reasonable addition, although one should really treat this kind of stuff within the CSV file (much more flexible, much more easy to manipulate). I've modified the attached script anyhow, though -- thanks for the hint!

expception thrown, but user added anyway?

Posted by David Bremner at March 1, 2007 - 19:34
I have a weird experience: I get
Couldn't add userid: The login name you selected is already in use or is not valid. Please choose another.

my users.csv is

password;userid;Lastname;Firstname;email@somewhere.com

okay, not real data, but should be syntactically OK.

The weirdest part is that the user seems to be added fine. I am using plone 2.5.2

need... more... input...

Posted by Tom Lazar at March 1, 2007 - 21:19
sorry, doesn't ring a bell. you'd have to provide more input. have you tried setting a breakpoint inside `portal_registration`s `addMember`? that should definitely provide you with something to act on.

invalid login name error

Posted by David Siedband at August 23, 2007 - 21:57
I had a this same error message. I found that it was caused by the quote marks (") that OpenOffice put in my csv. Once I search-and-removed those, the import script worked without a problem.

How about adding plone profile picture as well?

Posted by Ignacio Valdes at March 19, 2007 - 17:49
Is it possible to add a plone profile picture as well? If so, how? Thanks! -- IV

Some keywords.

Posted by Ignacio Valdes at March 19, 2007 - 17:53
So this can be found in search. This page refers to:

Bulk registration of plone users.
Bulk membership addition of plone users.
Mass registration of plone users.
Mass membership addition of plone users.
Bulk and mass user registration of members to plone from csv file.

Using e-mail's as member id's.

Posted by Ignacio Valdes at April 1, 2007 - 19:29
Hi, I'm using the MemberIDMonkeyPatch http://www.mxm.dk/products/public/memberidmonkeypatch/ to be able to have e-mail id's as member id's. When I try to execute importPASfromCSV I receive 'Couldn't add test@example.edu: The login name you selected is already in use or is not valid. Please choose another.' What can I do? Thanks, -- IV

Re: Using e-mail's as member id's.

Posted by Ignacio Valdes at April 1, 2007 - 19:33
FYI the id's are definitely not already in place, it is saying they are invalid despite the presence of the MemberIDMonkeyPatch. -- IV

Script does not work

Posted by Marcel Hilzinger at June 26, 2007 - 13:27
Plone Version 2.5.3
Error message:
2007-06-26T15:21:10 ERROR Zope.SiteErrorLog http://192.168.1.89:8080/importPASfromCSV
Traceback (innermost last):
Module ZPublisher.Publish, line 115, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 41, in call_object
Module Shared.DC.Scripts.Bindings, line 311, in __call__
Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 326, in _exec
Module None, line 14, in importPASfromCSV
- <PythonScript at /importPASfromCSV>
- Line 14
Module Products.CMFCore.utils, line 82, in getToolByName
AttributeError: portal_registration

What did I wrong?
Thanks

It works :-)

Posted by Marcel Hilzinger at June 26, 2007 - 13:38
Sorry. I did try to add the users to the zope db instead of the plone instance.
So it works.

CSV also from OpenOffice.org Calc

Posted by Andreas Mantke at July 30, 2007 - 18:42
First thanks for the skript.
I would like to add that not only Excel is able to save in CSV-Files. I created my test-csv-file with OpenOffice.org Calc, another OpenSource-Software (License: LGPL). In the saving-dialog I had only to ask the questions for the seperator (;) and whether there should be quotations around the strings.

Adding Location Field

Posted by Felix Kreativ at August 26, 2008 - 16:03
In plone 3.1.4
I used the method and works great "as it is", but when i tryed to add also the location to the users doesnt work anymore.
So looks my version:


<scripttext>
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) == 6:
passwd, id, last, first, email, location = tokens
properties = {
'username' : id,
'fullname' : '%s %s' % (first, last),
'email' : email.strip(),
'location' : location,
}
try:
regtool.addMember(id, passwd, properties=properties)
print "Successfully added %s %s (%s) with email %s" % (first, last, id, email, location)
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
</scripttext>

What i did wrong?

Thanks

Addition to support group assignment

Posted by Stephen Langenhoven at October 15, 2008 - 20:03
I had an additional requirement to also auto-assign users to a group while they were being created. I did that by modifying Tom's script as follows:

from Products.CMFCore.utils import getToolByName
users = context['users.csv'].data.split('\n')
regtool = getToolByName(context, 'portal_registration')
+ grouptool = getToolByName(context, 'portal_groups')
index = 1
imported_count = 0
+ grp = grouptool.getGroupById('<insert the name of your group here>')

for user in users:
tokens = user.split(';')
***************
*** 28,33 ****
--- 30,37 ----
regtool.addMember(id, passwd, properties=properties)
print "Successfully added %s %s (%s) with email %s" % (first, last, id, email)
imported_count += 1
+ grp.addMember(id)
+ print "Successfully added %s %s to the group %s" % (first, last, 'ShipmentConfirmers')
except ValueError, e:
print "Couldn't add %s: %s" % (id, e)
else:

As you can see the group is hard-coded - it would be trivial to extend that to a parameter based approach (additional fields on each line indicating the required groups?), but this met my needs.

Addition to support group assignment

Posted by Stephen Langenhoven at October 15, 2008 - 20:04
I had an additional requirement to also auto-assign users to a group while they were being created. I did that by modifying Tom's script as follows:

from Products.CMFCore.utils import getToolByName
users = context['users.csv'].data.split('\n')
regtool = getToolByName(context, 'portal_registration')
+ grouptool = getToolByName(context, 'portal_groups')
index = 1
imported_count = 0
+ grp = grouptool.getGroupById('<insert the name of your group here>')

for user in users:
tokens = user.split(';')
***************
*** 28,33 ****
--- 30,37 ----
regtool.addMember(id, passwd, properties=properties)
print "Successfully added %s %s (%s) with email %s" % (first, last, id, email)
imported_count += 1
+ grp.addMember(id)
+ print "Successfully added %s %s to the group %s" % (first, last, 'ShipmentConfirmers')
except ValueError, e:
print "Couldn't add %s: %s" % (id, e)
else:

As you can see the group is hard-coded - it would be trivial to extend that to a parameter based approach (additional fields on each line indicating the required groups?), but this met my needs.

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by