[Checkins] SVN: Zope3/trunk/src/zope/app/ Change
zope.app.preference.preference and
zope.app.container.browser.contents
Jacob Holm
jh at improva.dk
Fri Feb 23 10:05:12 EST 2007
Log message for revision 72783:
Change zope.app.preference.preference and zope.app.container.browser.contents
to adapt to IAnnotations instead of using an IPrincipalAnnotationUtility
directly.
Changed:
U Zope3/trunk/src/zope/app/container/browser/contents.py
U Zope3/trunk/src/zope/app/container/browser/tests/test_contents.py
U Zope3/trunk/src/zope/app/preference/README.txt
U Zope3/trunk/src/zope/app/preference/preference.py
-=-
Modified: Zope3/trunk/src/zope/app/container/browser/contents.py
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/contents.py 2007-02-23 13:10:34 UTC (rev 72782)
+++ Zope3/trunk/src/zope/app/container/browser/contents.py 2007-02-23 15:05:12 UTC (rev 72783)
@@ -30,11 +30,11 @@
from zope.copypastemove.interfaces import IPrincipalClipboard
from zope.copypastemove.interfaces import IObjectCopier, IObjectMover
from zope.copypastemove.interfaces import IContainerItemRenamer
+from zope.annotation.interfaces import IAnnotations
from zope.app import zapi
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.i18n import ZopeMessageFactory as _
-from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
from zope.app.container.browser.adding import Adding
from zope.app.container.interfaces import IContainer, DuplicateIDError
@@ -456,6 +456,5 @@
def getPrincipalClipboard(request):
"""Return the clipboard based on the request."""
user = request.principal
- annotationutil = zapi.getUtility(IPrincipalAnnotationUtility)
- annotations = annotationutil.getAnnotations(user)
+ annotations = IAnnotations(user)
return IPrincipalClipboard(annotations)
Modified: Zope3/trunk/src/zope/app/container/browser/tests/test_contents.py
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/tests/test_contents.py 2007-02-23 13:10:34 UTC (rev 72782)
+++ Zope3/trunk/src/zope/app/container/browser/tests/test_contents.py 2007-02-23 15:05:12 UTC (rev 72783)
@@ -30,8 +30,6 @@
from zope.app.component.testing import PlacefulSetup
from zope.app.container.contained import contained
-from zope.app.principalannotation import PrincipalAnnotationUtility
-from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
from zope.app.testing import ztapi
from zope.app.container.interfaces import IContainer, IContained
@@ -57,8 +55,8 @@
ztapi.provideAdapter(IAnnotations, IPrincipalClipboard,
PrincipalClipboard)
- ztapi.provideUtility(IPrincipalAnnotationUtility,
- PrincipalAnnotationUtility())
+ ztapi.provideAdapter(Principal, IAnnotations,
+ PrincipalAnnotations)
def testInfo(self):
# Do we get the correct information back from ContainerContents?
@@ -171,7 +169,22 @@
id = 'bob'
+class PrincipalAnnotations(dict):
+ implements(IAnnotations)
+ data = {}
+ def __new__(class_, context):
+ try:
+ annotations = class_.data[context.id]
+ except KeyError:
+ annotations = dict.__new__(class_)
+ class_.data[context.id] = annotations
+ return annotations
+ def __init__(self, context):
+ pass
+ def __repr__(self):
+ return "<%s.PrincipalAnnotations object>" % __name__
+
class TestCutCopyPaste(PlacefulSetup, TestCase):
def setUp(self):
@@ -184,8 +197,8 @@
ztapi.provideAdapter(IAnnotations, IPrincipalClipboard,
PrincipalClipboard)
- ztapi.provideUtility(IPrincipalAnnotationUtility,
- PrincipalAnnotationUtility())
+ ztapi.provideAdapter(Principal, IAnnotations,
+ PrincipalAnnotations)
def testRename(self):
container = traverse(self.rootFolder, 'folder1')
Modified: Zope3/trunk/src/zope/app/preference/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/preference/README.txt 2007-02-23 13:10:34 UTC (rev 72782)
+++ Zope3/trunk/src/zope/app/preference/README.txt 2007-02-23 15:05:12 UTC (rev 72783)
@@ -77,8 +77,7 @@
>>> settings.skin #doctest:+ELLIPSIS
Traceback (most recent call last):
...
- ComponentLookupError:
- (<InterfaceClass ...interfaces.IPrincipalAnnotationUtility>, '')
+ NoInteraction
So why did the lookup fail? Because we have not specified a principal yet, for
@@ -100,20 +99,25 @@
>>> import zope.security.management
>>> zope.security.management.newInteraction(participation)
-We also need a principal annotations utility, in which we store the settings:
+We also need an IAnnotations adapter for principals, so we can store the
+settings:
- >>> from zope.app.principalannotation.interfaces import \
- ... IPrincipalAnnotationUtility
+ >>> from zope.annotation.interfaces import IAnnotations
>>> class PrincipalAnnotations(dict):
- ... zope.interface.implements(IPrincipalAnnotationUtility)
- ...
- ... def getAnnotations(self, principal):
- ... return self.setdefault(principal, {})
+ ... zope.interface.implements(IAnnotations)
+ ... data = {}
+ ... def __new__(class_, context):
+ ... try:
+ ... annotations = class_.data[context.id]
+ ... except KeyError:
+ ... annotations = dict.__new__(class_)
+ ... class_.data[context.id] = annotations
+ ... return annotations
+ ... def __init__(self, context):
+ ... pass
- >>> annotations = PrincipalAnnotations()
-
>>> from zope.app.testing import ztapi
- >>> ztapi.provideUtility(IPrincipalAnnotationUtility, annotations)
+ >>> ztapi.provideAdapter(Principal, IAnnotations, PrincipalAnnotations)
Let's now try to access the settings again:
Modified: Zope3/trunk/src/zope/app/preference/preference.py
===================================================================
--- Zope3/trunk/src/zope/app/preference/preference.py 2007-02-23 13:10:34 UTC (rev 72782)
+++ Zope3/trunk/src/zope/app/preference/preference.py 2007-02-23 15:05:12 UTC (rev 72783)
@@ -24,12 +24,12 @@
from zope.security.management import getInteraction
from zope.traversing.interfaces import IContainmentRoot
from zope.location import LocationProxy, locate, Location
+from zope.annotation.interfaces import IAnnotations
import zope.app.component.hooks
from zope.app import zapi
from zope.app.container.contained import Contained
from zope.app.container.interfaces import IReadContainer
-from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
from zope.app.preference.interfaces import IPreferenceGroup
from zope.app.preference.interfaces import IPreferenceCategory
@@ -174,10 +174,9 @@
del self.__dict__[key]
def data(self):
- utility = zapi.getUtility(IPrincipalAnnotationUtility, context=self)
# TODO: what if we have multiple participations?
principal = getInteraction().participations[0].principal
- ann = utility.getAnnotations(principal)
+ ann = IAnnotations(principal)
# If no preferences exist, create the root preferences object.
if ann.get(pref_key) is None:
More information about the Checkins
mailing list