Personal tools
You are here: Home Documentation How-tos Export member data to CSV
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

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

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.

  1. 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
    
  2. 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
  3. 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.

  1. 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
    

  2. 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
  3. 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.

by David Bain last modified May 12, 2008 - 21:50 All content is copyright Plone Foundation and the individual contributors.

Does this work for Plone 2.5.x?

Posted by Barry Page at March 19, 2007 - 22:37
I followed this recipe and got the stunning result of "fullname, login, password, email"!
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.

No promises for Plone 2.5.x

Posted by David Bain at April 9, 2007 - 12:52
I've been extremely busy, so following the principals of stuctured procrastination (http://www.structuredprocrastination.com/), I took the time to extend this howto with instructions for member export under Plone 2.5.x.

Extended for Plone 2.5.x

Posted by David Bain at April 9, 2007 - 12:50
I've been extremely busy, so following the principals of stuctured procrastination (http://www.structuredprocrastination.com/), I too the time to extended this howto with instructions for member export under Plone 2.5.x.

Still doesn't work for me...

Posted by Barry Page at May 17, 2007 - 01:48
Thanks David, but I still just get the headings. I tried to strip the script back to bare essentials but no luck. :-(
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!

Posted by David Bain at May 17, 2007 - 14:50
wow.. I was released from prison, great! One day I should visit New Zealand to get the full story from the authorities there :)

Still Doesn't work

Posted by Natalie Morris at May 18, 2007 - 19:05
I too have tried this and am getting nothing more than "fullname, login, password, email"

Making Export Member work with Plone 2.5

Posted by John Knight at July 1, 2007 - 20:50
I also got the stunning results of "fullname, login, password, email" and nothing else. Some minor modifications to the code appear to work. I am however unable to extract the password; is it possible to extract passwords? Whilst the code may not be the best, it does seem to work.

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

Posted by John Knight at July 1, 2007 - 20:54
Apologies. The identation has gone when saving the comment and I do not know how to ensure that it stays. Clearly the above code will not work without indentation.

still not working

Posted by neha at August 23, 2007 - 08:43
i tested this piece of code with proper indentation in Plone 2.5.2 bt still i'm getting only the headings.Wht to do?

Works in 2.5.3

Posted by Dale Alexander at January 9, 2008 - 18:40
First of all, thank you John for the modifications. The script works with when the appropriate indentations are applied (use the original scripts to get an idea of where to indent.

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!!

Posted by Mohd Izhar Firdaus Ismail at May 12, 2008 - 19:46
I spent some time hunting the password hash, and after a few hours, I found it.

Code available in the link below. Tested on Plone3.0.5.

http://blog.kagesenshi.org/2008/05/exporting-plone30-memberdata-and.html

rewrite and mailman integration

Posted by Guido A.J. Stevens at March 11, 2008 - 17:25
I've rewritten this script and hooked it up to sync with Mailman. Tutorial and sources available at http://transcyberia.info/archives/23-howto-sync-mailman-from-plone.html

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