[Zope3-dev] Principal with annotations
Florian Lindner
mailinglists at xgm.de
Sat Sep 25 14:32:59 EDT 2004
Stephan Richter schrieb:
>On Friday 24 September 2004 11:09, Florian Lindner wrote:
>
>
>>This chapter is pretty new, isn't it? When I worked through the Zope3
>>book some months ago I didn't noticed such a chapter.
>>
>>
> <>
> Yes, it was suggested by Kapil and I added it just before turning in
> the book
> to the publisher.
Ok, I've used you're example, but when I try to save a entry in the
email field (in User Info) of a new principal:
File "C:\Python23\Lib\site-packages\zope\app\form\browser\widget.py",
line 31
, in applyChanges
field.set(content, value)
File "C:\Python23\Lib\site-packages\zope\schema\_bootstrapfields.py",
line 18
, in set
setattr(object, self.__name__, value)
File "C:\zope\lib\python\CSUser\info.py", line 27, in __setattr__
self.info[name] = value
File "C:\zope\lib\python\CSUser\info.py", line 23, in __getattr__
raise AttributeError, "'%s' not in interface." %name
AttributeError: 'info' not in interface.
127.0.0.1 - zope.manager [25/Sep/2004:20:58:10 +0400] "POST
/++etc++site/defaul
/AuthenticationService/PrincipalSource/anmeldung/@@userInfo.html
HTTP/1.1" 200
92
"http://localhost:8080/++etc++site/default/AuthenticationService/PrincipalSo
rce/anmeldung/@@userInfo.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1;
de-DE;
rv:1.7) Gecko/20040803 Firefox/0.9.3"
127.0.0.1 - zope.manager [25/Sep/2004:20:58:11 +0400] "GET
/++etc++site/default
AuthenticationService/PrincipalSource/anmeldung/@@singleBranchTree.xml
HTTP/1.1
200 1066 "" "Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.7)
Gecko/200
0803 Firefox/0.9.3"
This is my interfaces.py:
from zope.i18n import MessageIDFactory
from zope.interface import Interface
from zope.schema import TextLine
_ = MessageIDFactory('principalinfo')
class IPrincipalInformation(Interface):
"""This interface stores additional information about a principal."""
email = TextLine(
title=_("E-mail"),
description=_("E-mail Address"),
# default=u"",
required=True)
My info.py:
from persistent.dict import PersistentDict
from zope.interface import implements
from zope.app import zapi
from interfaces import IPrincipalInformation
key = 'CSUser'
class PrincipalInformation(object):
r"""Principal Information Adapter"""
implements(IPrincipalInformation)
def __init__(self, principal):
annotationsvc = zapi.getService('PrincipalAnnotation')
annotations = annotationsvc.getAnnotations(principal)
if annotations.get(key) is None:
annotations[key] = PersistentDict()
self.info = annotations[key]
def __getattr__(self, name):
if name in IPrincipalInformation:
return self.info.get(name, None)
raise AttributeError, "'%s' not in interface." %name
def __setattr__(self, name, value):
if name in IPrincipalInformation:
self.info[name] = value
else:
super(PrincipalInformation, self).__setattr__(name, value)
What is wrong there?
One more question: Is it possible to create a new type of principal but
not to modify the existing one?
Thx,
Florian
More information about the Zope3-dev
mailing list