[Zope-CMF] Saving custom data in a MemberData-object from python

Shane Hathaway shane@digicool.com
Mon, 23 Apr 2001 10:41:16 -0400


Sigve Tjora wrote:
> I want to store a plain python dictionary, and not just for the
> authenticated user.
> 
> If I just store the dictionary in the user object, eg.
> 
> user=portal_membership.getAutehnticatedUser()
> user.myData={"id1":"data1", "id2":"data2"}
> 
> If I do it this way, the userobject "looses" this property when I restart
> Zope. Why is that? How can I store basic python-objects within the
> userobject?

The user object is not necessarily persistent, and not necessarily
created on the fly either.  (Redundancy for emphasis.)  You can't tack
on properties on a user object and expect them to be saved since the
users might come from a non-persistent source like an LDAP database. 
Similarly, you can't tack on properties and expect that they *won't* be
saved, so you shouldn't try to remap user roles this way (which the
portal_membership does right now if you use the role mapping form--that
part needs to be redone.)

However, *member* objects are always persistent.  Member objects
correspond to user objects, but since user objects are not necessarily
persistent, a "member" class can't use "user" as a base class.  So what
you really want is:

m=portal_membership.getAuthenticatedMember()
m.myData={"id1":"data1", "id2":"data2"}

Now, I can't guarantee this will work either. :-)  But in theory it
could work reliably.

Shane