Skip to content

Instantly share code, notes, and snippets.

@l34marr

l34marr/getMember.py

Last active Aug 29, 2015
Embed
What would you like to do?
Add Plone Members Programmatically, Tested on Plone 4.3.3. Prepare Your Own member.csv, and Run bin/plonectl run regBatch.py
from Products.CMFCore.utils import getToolByName
membership = getToolByName(app.mysite, 'portal_membership')
for member in membership.listMembers():
print member.getProperty('id'), member.getProperty('fullname'), member.getProperty('email')
user1 pass1 User One user1@gmail.com
user2 pass2 測試 user2@gmail.com
from Testing import makerequest
root = makerequest.makerequest(app)
site = root.mysite
admin = root.acl_users.getUserById('admin')
admin = admin.__of__(site.acl_users)
from AccessControl.SecurityManagement import newSecurityManager
newSecurityManager(None, admin)
#from zope.site.hooks import setHooks
from zope.site.hooks import setSite
#setHooks()
#site.setupCurrentSkin(site.REQUEST)
setSite(site)
from Products.CMFCore.utils import getToolByName
regtool = getToolByName(site, 'portal_registration')
#username = 'testuser'
#password = 'topsecret'
#properties = {'username': username, 'fullname': 'Test User', 'email': 'testuser@gmail.com'}
import csv
with open('member.csv', 'rb') as f:
f.seek(0)
reader = csv.reader(f)
for row in reader:
#member = regtool.addMember(username, password, properties=properties)
member = regtool.addMember(row[0], row[1], properties={'username': row[0], 'fullname': row[2], 'email': row[3]})
import transaction
transaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.