Export member data to CSV
This How-to applies to:
Plone 2.5.x, Plone 2.1.x, Plone 2.0.x
This How-to is intended for:
Site Administrators, Integrators, Customizers, Developers
Important: There are two scripts listed below. Ensure that you choose the version of the script that works with your version of Plone.
Also, you may want to check out a more up to date version of this by Guido A.J. Stevens
For Plone 2.0.x and 2.1.x
The following has been tested and is known to work on Plone 2.1.x and should work on Plone 2.0.x
getPassword() cannot be run in a through-the-web python script. As a result you will need to create an external method.
-
Use the script below, name it something like 'member_list.py' and save it on the filesystem under your 'Plone Instance' > 'Extensions' folder.
You can make adjustments to the script for custom member properties
def getMembers(self): """ get a csv of site members """ from Products.CMFCore.utils import getToolByName text = '' # add the member properties you want below # this is a good place to account for custom member properties memberProperties = [] memberProperties.insert(0, 'fullname') #memberProperties.insert(1, 'last_login_time') #memberProperties.insert(1, 'login_time') memberProperties.insert(1, 'login') memberProperties.insert(2, 'password') memberProperties.insert(3, 'email') #memberProperties.insert(4, 'emailPermission') membership = getToolByName(self, 'portal_membership') for p in memberProperties: #write out the first line text += p + ', ' #remove trailing comma text=text[:-2] text += chr(13)+chr(10) #first line has been written for member in membership.listMembers(): #try to filter out bogus members if '@' in getattr(member, 'email') and len(getattr(member, 'fullname')) > 2: #check if permission is granted to send email for p in memberProperties: if p == 'email': #you will need to alter the line below, to ensure that you return the custom properties you need text+='%s,%s,%s,%s' % (getattr(member, 'fullname'), getattr(member, 'name'), str(member.getPassword()).strip(),getattr(member, 'email')) if len(getattr(member,'fullname')) > 1: text+='\n' return text -
In the Zope Management Interface (ZMI) of your plone site create an external method to call the 'member_list' script with the following settings:
id: member_list Module Name: member_list Title: Member List Function Name: getMembers
-
After saving this new method click the 'Test' tab to run the method. The result will be a CSV list of all your site members and their data.
important! for security make sure that only Managers can run and view this script.
For Plone 2.5.x
The following has been tested on Plone 2.5.2 and should work on any version of Plone 2.5.x
getPassword() cannot be run in a through-the-web python script. As a result you will need to create an external method.
-
Use the script below, name it something like 'member_list.py' and save it on the filesystem under your 'Plone Instance' > 'Extensions' folder.
You can make adjustments to the script for custom member properties
def getMembers(self): """ get a csv of site members """ from Products.CMFCore.utils import getToolByName text = '' # add the member properties you want below # this is a good place to account for custom member properties memberProperties = [] memberProperties.insert(0, 'fullname') #memberProperties.insert(1, 'last_login_time') #memberProperties.insert(1, 'login_time') memberProperties.insert(1, 'login') memberProperties.insert(2, 'password') memberProperties.insert(3, 'email') #memberProperties.insert(4, 'emailPermission') membership = getToolByName(self, 'portal_memberdata') for p in memberProperties: #write out the first line text += p + ', ' #remove trailing comma text=text[:-2] text += chr(13)+chr(10) #first line has been written for member in membership.folderlistingFolderContents(): #listMembers(): #try to filter out bogus members if member.getPortalTypeName() == 'Member': if '@' in getattr(member, 'email') and len(getattr(member, 'fullname')) > 2: #check if permission is granted to send email for p in memberProperties: if p == 'email': #you will need to alter the line below, to ensure that you return the custom properties you need text+='%s,%s,%s,%s' % (getattr(member, 'fullname'), getattr(member,'id'), str(member.getPassword()).strip(),getattr(member, 'email')) if len(getattr(member,'fullname')) > 1: text+='\n' return text -
In the Zope Management Interface (ZMI) of your plone site create an external method to call the 'member_list' script with the following settings:
id: member_list Module Name: member_list Title: Member List Function Name: getMembers
-
After saving this new method click the 'Test' tab to run the method. The result will be a CSV list of all your site members and their data.
important! for security make sure that only Managers can run and view this script.
No promises for Plone 2.5.x
Extended for Plone 2.5.x
Still doesn't work for me...
And congratulations on your recent release from prison (http://www.nzherald.co.nz/feature/index.cfm?c_id=1500919) which is big news in New Zealand.
sweet!
Still Doesn't work
Making Export Member work with Plone 2.5
def getMembers(self):
""" get a csv of site members """
from Products.CMFCore.utils import getToolByName
text = ''
# add the member properties you want below
# this is a good place to account for custom member properties
memberProperties = []
memberProperties.insert(0, 'fullname')
#memberProperties.insert(1, 'last_login_time')
#memberProperties.insert(1, 'login_time')
memberProperties.insert(1, 'login')
memberProperties.insert(2, 'password')
memberProperties.insert(3, 'email')
#memberProperties.insert(4, 'emailPermission')
for p in memberProperties:
#write out the first line
text += p + ', '
#remove trailing comma
text=text[:-2]
#write first line with carriage return and line feed
text += chr(13)+chr(10)
membership=self.portal_membership
for memberId in membership.listMemberIds():
#try to filter out bogus members
member=membership.getMemberById(memberId)
#if member.getPortalTypeName() == 'Member':
if '@' in member.getProperty('email') and len(member.getProperty('fullname')) > 2: #check if permission is granted to send email
for p in memberProperties:
if p == 'email':
#you will need to alter the line below, to ensure that you return the custom properties you need
text+='%s,%s,%s,%s' % (member.getProperty('fullname'), getattr(member,'id'), member.getProperty('password'),member.getProperty('email'))
if len(member.getProperty('fullname')) > 1:
text+='\n'
return text
indentation
still not working
Works in 2.5.3
Have you been able to get it to find a solution for presenting the passwords?
To neha_4949: in case the script is still not working, please go through John's version carefully. Note that in most cases "getattr" has been changed to "member.getProperty" or a variation of that. Once you make those changes are are careful with the indentation, the script should work.
For Plone3.0 .. and Passwords!!
Code available in the link below. Tested on Plone3.0.5.
http://blog.kagesenshi.org/2008/05/exporting-plone30-memberdata-and.html
Does this work for Plone 2.5.x?
I notice that this how-to is tagged as 2.0 and 2.1, and of course we've gone from GRUF to PAS in the meantime.