[Zope3-Users] Principal annotations

Tom Dossis td at yoma.com.au
Thu Mar 9 04:21:03 EST 2006


Shane Hathaway wrote:
> Your idea of annotating InternalPrincipals rather than Principals seems
> to work, but I apparently did something wrong, because edited
> annotations don't persist!  I can save edits, but when I reload the
> page, they're gone.  I don't know why.
> 

A quick test, hope it helps...

 >>> from zope.app.authentication.principalfolder import InternalPrincipal
 >>> from zope.app.annotation import IAttributeAnnotatable
 >>> from zope.interface import classImplements
 >>> classImplements(InternalPrincipal, IAttributeAnnotatable)
 >>> annotations = IAnnotations(principal)
 >>> annotations
{}
 >>> from persistent.dict import PersistentDict
 >>> annotations['mykey'] = PersistentDict()
 >>> info = annotations['mykey']
 >>> info['abc'] = 123
 >>> import transaction
 >>> transaction.commit()
 >>> ^D


 >>> site=root['f2l']
 >>> sm = site.getSiteManager()
 >>> pf = sm['tools']['PluggableAuthentication']['PrincipalFolder']
 >>> principal = pf['1']
 >>> principal.__annotations__
<BTrees._OOBTree.OOBTree object at 0x4190f974>
 >>> principal.__annotations__['mykey']
<persistent.dict.PersistentDict object at 0x4178496c>
 >>> principal.__annotations__['mykey']['abc']
123




More information about the Zope3-users mailing list