Export member data to CSV
A quick step by step on exporting your Plone member data as a comma separated file.
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 textIn 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 textIn 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.
