quick search:
 

*SIMPLE* add custom memberdata

Submitted by: runyaga
Last Edited: 2004-10-14

Category: CMF

Average rating is: 4.0 out of 5 (1 ratings)

Description:
a very simple approach to adding a field to the CMF memberdata. the previous one was *way* too complex. here is the bare essentials to add a new field, fullname.



Source (Text):
#from within CMF management screen (/manage)

#click on portal_memberdata, click on properties
#add a string field called fullname

#click Find tab, type join_form, and click find
#add a field called fullname

#your done, at the root of the CMF you can create a Script (Python)
#called getAllMemberDataAsCSV, which will list in CSV form all members
#and their attributes

#prints out a CSV pf member and member properties
text = ''
memberProperties = context.portal_memberdata.propertyIds()
memberProperties.insert(0, 'id')

for p in memberProperties:
    #write out the first line
    text += p + ', '

text += '\n' #first line has been written

for member in context.portal_membership.listMembers():
    for p in memberProperties:
        if hasattr(member, p): text+=str(getattr(member,p))
        text+=', '
    text+='\n'

return text

Explanation:
very simple. the previous one was overly complex and was something very
specific to what I had done. this is the simpliest case that works. you
can do all of this 'through the web' which is ZOPE's greatest strength.

NOTE: recent versions of CMF (out of CVS and 1.1) have API information
in the ZOPE Help screens.


Comments:

Editing extra info? by grifter - 2004-10-14
This seems to work well-- would anyone care to
comment on how to add the ability to edit this
extra info after it's been initially added?

--dave
 
Re: Editing extra info? by runyaga - 2004-10-14
uhm. you can try exUserFolder and use the cmfPropSource, give it a whirl ;)
 
Re: Editing extra info? by mark - 2004-10-14
You must customize the personalize_form.

Add the following to the form in an appropriate spot:

 <tr>
  <th> Full Name<br>(Optional)
  </th>
  <td>
   <input type="text" name="fullname" size="30" 
          value="<dtml-var "member.getProperty( 'fullname' )" html_quote>">
  </td>
 </tr> 
 
Re: Editing extra info? by dancam - 2004-10-14
I personalized my Plone personalize_form and join_form...

It was for me the occasion to make my first script!!! getMemberData
#click on portal_memberdata, click on properties
#add a string field called x, prenom, nom
#click Find tab, type join_form, and click find
#add a field called x
# x, chaine  nom de la propriété dont on cherche la valeur, chaine
# membre, chaine nom du membre listé
for member in context.portal_membership.listMembers():
    if membre == str(getattr(member, 'id')):
        if hasattr(member, x): text+=str(getattr(member,x)) 
return text

I use it in portal_skins/custom/member_search_results so that instead of the Pseudo, I have under the portrait of the member
the name and firstname  
<span class="card" tal:define="name result/getUserName;
                                           home python:container.portal_membership.getHomeUrl(name, verifyPermission=1);
                                           fullname python: here.portal_memberdata.getMemberData(name,'nom');
                                           firstname python: here.portal_memberdata.getMemberData(name,'prenom'); 
                                           portrait python: here.portal_membership.getPersonalPortrait(name);"> 

it could be used in the navigation box, in the personal Folder ...


Whatever his fullname, Thanks to runyaga for the tip :) 



removed by alfons - 2004-10-14


Doing it programmatically ? by BabyTux - 2004-10-14
Hey,

Is there a way to add the member property in the memberdatatool programmatically ?

Greetings,
Gitte Wange
 
Re: Doing it programmatically ? by runyaga - 2004-10-14
portal_memberdata is merely a PropertyManager.. use the source luke;
http://cvs.zope.org/Zope/lib/python/OFS/PropertyManager.py


here's an improved CSV creation script by cleath - 2004-10-14
#prints out a CSV pf member and member properties
#this makes a Microsoft CSV file-- use text delimiter="
text = ''
memberProperties = context.portal_memberdata.propertyIds()
memberProperties.insert(0, 'id')

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 context.portal_membership.listMembers():
    for p in memberProperties:
        if hasattr(member, p): 
            myAttr = getattr(member,p)
            if same_type(myAttr,[]):
                #it's a list
                text+='"%s"'%str(myAttr)
            elif same_type(myAttr,''):
                #it's a string
                mystr=str(myAttr)
                mystr = mystr.replace('"','""')
                text+='"%s"'%mystr
            else:
                text+='%s'%str(myAttr)

        text+=', '
    text=text[:-2]
    text+=chr(13)+chr(10)

return text