[Zope] Adding many users

Shane Hathaway shane@digicool.com
Wed, 10 Jan 2001 17:23:52 -0500


Ragnar Beer wrote:
> 
> Howdy Zopistas and happy new year!
> 
> I need to add about 150 users to an acl_users folder and I wouldn't
> like to do it manually since the data already exists in a python
> list. What would be an elegant way to add them all with a python
> script?

A script to put in lib/python, supplying your own user_role_name and
user_list:

user_list = ??
user_role_name = ??

import Zope
app = Zope.app()
folder = app.acl_users
for u in user_list:
  folder._doAddUser(u.name, u.password, (user_role_name,), ())
get_transaction().commit()

See how that works?  Those first two lines give you the actual
database--not just a special view of it but a live connection.  From
there, you don't use some funny mechanism to get acl_users--it's
actually a simple attribute of the root object.  Then you modify
acl_users however you want and commit the transaction.  If any error
occurs, the transaction will be aborted and changes made to the database
will be forgotten.

Beautiful, isn't it?

Shane