[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/presentation/ The
presentation service is gone.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Sep 17 12:15:36 EDT 2004
Log message for revision 27569:
The presentation service is gone.
Ripped out local presentation service implementation and use local adapter
service instead.
Changed:
U Zope3/trunk/src/zope/app/presentation/__init__.py
U Zope3/trunk/src/zope/app/presentation/browser/configure.zcml
U Zope3/trunk/src/zope/app/presentation/configure.zcml
U Zope3/trunk/src/zope/app/presentation/presentation.py
U Zope3/trunk/src/zope/app/presentation/tests/test_pagefolder.py
U Zope3/trunk/src/zope/app/presentation/tests/test_presentation.py
-=-
Modified: Zope3/trunk/src/zope/app/presentation/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/presentation/__init__.py 2004-09-17 16:15:33 UTC (rev 27568)
+++ Zope3/trunk/src/zope/app/presentation/__init__.py 2004-09-17 16:15:36 UTC (rev 27569)
@@ -19,4 +19,3 @@
from zope.app.presentation.presentation import IPageRegistration
from zope.app.presentation.presentation import PageRegistration
-from zope.app.presentation.presentation import LocalPresentationService
Modified: Zope3/trunk/src/zope/app/presentation/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/presentation/browser/configure.zcml 2004-09-17 16:15:33 UTC (rev 27568)
+++ Zope3/trunk/src/zope/app/presentation/browser/configure.zcml 2004-09-17 16:15:36 UTC (rev 27569)
@@ -1,13 +1,5 @@
<configure xmlns="http://namespaces.zope.org/browser">
- <addMenuItem
- class="...presentation.LocalPresentationService"
- description=
- "A Presentation Service allows you to register views, resources and skins"
- title="Presentation Service"
- permission="zope.ManageServices"
- />
-
<editform
schema="...presentation.IPageRegistration"
name="index.html"
Modified: Zope3/trunk/src/zope/app/presentation/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/presentation/configure.zcml 2004-09-17 16:15:33 UTC (rev 27568)
+++ Zope3/trunk/src/zope/app/presentation/configure.zcml 2004-09-17 16:15:36 UTC (rev 27569)
@@ -3,15 +3,6 @@
i18n_domain="zope"
>
-
-<content class=".presentation.LocalPresentationService">
- <factory />
- <require
- permission="zope.ManageServices"
- interface="zope.app.registration.interfaces.IRegistry"
- />
-</content>
-
<content class=".presentation.ViewRegistration">
<require
permission="zope.ManageServices"
Modified: Zope3/trunk/src/zope/app/presentation/presentation.py
===================================================================
--- Zope3/trunk/src/zope/app/presentation/presentation.py 2004-09-17 16:15:33 UTC (rev 27568)
+++ Zope3/trunk/src/zope/app/presentation/presentation.py 2004-09-17 16:15:36 UTC (rev 27569)
@@ -21,8 +21,6 @@
from zope.interface import implements, providedBy, Interface, Attribute
from zope.security.checker import NamesChecker, ProxyFactory
-from zope.component.presentation import IDefaultViewName
-from zope.component.presentation import PresentationRegistration
import zope.app.container.contained
import zope.app.registration.interfaces
@@ -30,7 +28,6 @@
import zope.app.adapter
import zope.app.interface.interfaces
import zope.component.interfaces
-import zope.component.presentation
import zope.configuration.exceptions
import zope.proxy
import zope.publisher.interfaces.browser
@@ -41,209 +38,12 @@
from zope.app.dependable.interfaces import IDependable, DependencyError
from zope.app.registration.interfaces import IRegistered
-# TODO: Skins and layer definitions are not handled by this service
-# but left up to services above, which effectively means the global
-# service. This problem will probably become obsolete when the
-# ImplementViewsAsAdapters proposal is implemented.
-
-class LocalPresentationService(
- zope.app.adapter.LocalAdapterBasedService,
- ):
-
- implements(
- zope.component.interfaces.IPresentationService,
- zope.app.site.interfaces.ISimpleService,
- zope.app.registration.interfaces.IRegistry,
- zope.app.interface.interfaces.IInterfaceBasedRegistry,
- )
-
- next = base = None
-
- def __init__(self):
- self.layers = persistent.dict.PersistentDict()
- self.base = zapi.getGlobalService(zapi.servicenames.Presentation)
-
- def setNext(self, next, global_):
- if next is None:
- self.delegate = global_
- else:
- self.delegate = next
-
- self.next = next
- self.base = global_
- for layername in self.layers:
- nextlayer = next.queryLayer(layername)
- globlayer = global_.queryLayer(layername)
- self.layers[layername].setNext(nextlayer, globlayer)
-
- def defaultSkin(self):
- return self.delegate.defaultSkin
- defaultSkin = property(defaultSkin)
-
- def querySkin(self, name):
- return self.delegate.querySkin(name)
-
- def queryLayer(self, name):
- r = self.layers.get(name)
- if r is not None:
- return r
- return self.delegate.queryLayer(name)
-
- def queryView(self, object, name, request, default=None,
- providing=Interface):
- """Look for a named view for a given object and request
-
- The request must implement `IPresentationRequest`.
-
- The default will be returned if the component can't be found.
- """
- skin = request.getPresentationSkin() or self.defaultSkin
- layers = self.querySkin(skin)
- if not layers:
- return default
-
- objects = object, request
- for layername in layers:
- layer = self.layers.get(layername)
- if layer is None:
- layer = self.delegate.queryLayer(layername)
- if layer is None:
- raise ValueError("Bad layer", layer)
-
- r = layer.queryMultiAdapter(objects, providing, name)
- if r is not None:
- return r
- return default
-
- def queryResource(self, name, request, default=None, providing=Interface):
- """Look up a named resource for a given request
-
- The request must implement `IPresentationRequest`.
-
- The default will be returned if the component can't be found.
- """
- skin = request.getPresentationSkin() or self.defaultSkin
- layers = self.querySkin(skin)
- if not layers:
- return default
-
- for layername in layers:
- layer = self.layers.get(layername)
- if layer is None:
- layer = self.delegate.queryLayer(layername)
- if layer is None:
- raise ValueError("Bad layer", layer)
-
- r = layer.queryAdapter(request, providing, name)
- if r is not None:
- return r
-
- return default
-
- def queryMultiView(self, objects, request,
- providing=Interface, name='',
- default=None):
- """Adapt the given objects and request
-
- The first argument is a sequence of objects to be adapted with the
- request.
- """
-
- skin = request.getPresentationSkin() or self.defaultSkin
- layers = self.querySkin(skin)
- if not layers:
- return default
-
- objects = objects + (request, )
- for layername in layers:
- layer = self.layers.get(layername)
- if layer is None:
- layer = self.delegate.queryLayer(layername)
- if layer is None:
- raise ValueError("Bad layer", layer)
-
- r = layer.queryMultiAdapter(objects, providing, name)
- if r is not None:
- return r
- return default
-
- def queryDefaultViewName(self, object, request, default=None):
- skin = request.getPresentationSkin() or self.defaultSkin
- layers = self.querySkin(skin)
- if not layers:
- return default
-
- objects = object, request
- for layername in layers:
- layer = self.layers.get(layername)
- if layer is None:
- layer = self.delegate.queryLayer(layername)
- if layer is None:
- raise ValueError("Bad layer", layer)
- r = layer.lookup(map(providedBy, objects),
- IDefaultViewName)
- if r is not None:
- return r
- return default
-
- def queryRegistrationsFor(self, registration, default=None):
- layername = registration.layer
- layer = self.layers.get(layername)
- if layer is None:
- return default
- return layer.queryRegistrationsFor(registration, default)
-
- def createRegistrationsFor(self, registration):
- layername = registration.layer
- layer = self.layers.get(layername)
- if layer is None:
- if self.next is None:
- next = None
- else:
- next = self.next.queryLayer(layername)
- base = self.base.queryLayer(layername)
- if base is None:
- raise ValueError("Undefined layer", layername)
- layer = LocalLayer(base, next, self, layername)
- self.layers[layername] = layer
-
- return layer.createRegistrationsFor(registration)
-
- def registrations(self, localOnly=False):
- for layer in self.layers.itervalues():
- for registration in layer.registrations():
- yield registration
-
- if localOnly is True:
- return
-
- next = self.next
- if next is None:
- next = self.base
-
- for registration in next.registrations():
- yield registration
-
- def getRegistrationsForInterface(self, required):
- iro = required.__iro__ + (None,)
-
- for registration in self.registrations():
- if IViewRegistration.providedBy(registration):
- if registration.required in iro:
- yield registration
-
- if isinstance(registration, PresentationRegistration):
- if registration.required[0] in iro:
- # Not using an adapter here, since it would be just
- # overhead.
- yield GlobalViewRegistration(registration)
-
class GlobalViewRegistration(object):
"""Registrations representing global view service thingies."""
implements(zope.app.registration.interfaces.IRegistration)
- serviceType = zapi.servicenames.Presentation
+ serviceType = zapi.servicenames.Adapters
status = zope.app.registration.interfaces.ActiveStatus
def __init__(self, context):
@@ -316,7 +116,7 @@
class ViewRegistration(zope.app.registration.registration.SimpleRegistration):
implements(IViewRegistration)
- serviceType = zapi.servicenames.Presentation
+ serviceType = zapi.servicenames.Adapters
provided = Interface
# For usageSummary(); subclass may override
Modified: Zope3/trunk/src/zope/app/presentation/tests/test_pagefolder.py
===================================================================
--- Zope3/trunk/src/zope/app/presentation/tests/test_pagefolder.py 2004-09-17 16:15:33 UTC (rev 27568)
+++ Zope3/trunk/src/zope/app/presentation/tests/test_pagefolder.py 2004-09-17 16:15:36 UTC (rev 27569)
@@ -21,13 +21,11 @@
from zope.app.site.tests.placefulsetup import PlacefulSetup
from zope.app.presentation.pagefolder import PageFolder, IPageFolder
from zope.app.presentation.zpt import ZPTTemplate
-from zope.app.presentation import LocalPresentationService
from zope.app.registration.interfaces import ActiveStatus
from zope.interface import Interface
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app.registration.tests.test_registrationmanager \
import RegisterableContainerTests
-from zope.component.servicenames import Presentation
from zope.app.dependable.interfaces import IDependable
from zope.app.annotation.interfaces import IAttributeAnnotatable
@@ -35,9 +33,9 @@
from zope.app import zapi
from zope.app.annotation.interfaces import IAnnotations, IAnnotatable
from zope.app.annotation.attribute import AttributeAnnotations
+from zope.app.adapter.adapter import LocalAdapterService
-
class I(Interface):
pass
@@ -48,17 +46,13 @@
def setUp(self):
sm = PlacefulSetup.setUp(self, site=True)
- zapi.getGlobalService(Presentation).defineLayer('debug')
- setup.addService(sm, Presentation, LocalPresentationService(),
- suffix='service')
+ setup.addService(sm, zapi.servicenames.Adapters,
+ LocalAdapterService(), suffix='service')
default = zapi.traverse(self.rootFolder, '++etc++site/default')
- ztapi.provideAdapter(IAnnotatable, IAnnotations,
- AttributeAnnotations)
+ ztapi.provideAdapter(IAnnotatable, IAnnotations, AttributeAnnotations)
+ ztapi.provideAdapter(IAnnotatable, IDependable, Dependable)
- ztapi.provideAdapter(IAnnotatable, IDependable,
- Dependable)
-
default["PF"] = PageFolder()
pagefolder = zapi.traverse(default, "PF")
Modified: Zope3/trunk/src/zope/app/presentation/tests/test_presentation.py
===================================================================
--- Zope3/trunk/src/zope/app/presentation/tests/test_presentation.py 2004-09-17 16:15:33 UTC (rev 27568)
+++ Zope3/trunk/src/zope/app/presentation/tests/test_presentation.py 2004-09-17 16:15:36 UTC (rev 27569)
@@ -29,13 +29,11 @@
from zope.app.folder import rootFolder
from zope.app.presentation.zpt import IZPTTemplate
from zope.app.site.service import ServiceManager
-from zope.app.servicenames import Presentation
from zope.app.registration.tests.iregistry import TestingIRegistry
from zope.app.site.tests.placefulsetup import PlacefulSetup
from zope.app.presentation.presentation import ViewRegistration
from zope.app.presentation.presentation import PageRegistration
from zope.app.presentation.presentation import BoundTemplate
-from zope.app.presentation.presentation import LocalPresentationService
from zope.app.presentation.presentation import IPageRegistration
from zope.app.presentation.presentation import PageRegistrationAddSubscriber
from zope.app.presentation.presentation import PageRegistrationRemoveSubscriber
@@ -44,7 +42,6 @@
from zope.component.exceptions import ComponentLookupError
from zope.component.interfaces import IServiceService
-from zope.component.interfaces import IPresentationService
from zope.app.tests import ztapi
from zope.configuration.exceptions import ConfigurationError
@@ -81,7 +78,7 @@
requestType = I2
name = 'test'
layer = 'default'
- serviceType = Presentation
+ serviceType = zapi.servicenames.Adapters
provided = Interface
with = property(lambda self: (self.requestType, ))
@@ -124,220 +121,7 @@
run = PhonyTemplate()
-class TestLocalPresentationService(PlacefulSetup, TestingIRegistry, TestCase):
- def setUp(self):
- sm = PlacefulSetup.setUp(self, site=True)
- self._service = setup.addService(sm, Presentation,
- LocalPresentationService())
-
- def test_defaultSkin(self):
- # We don't let people set the default skin locally yet.
- # So just test that we can get the default from the global service
- zapi.getGlobalService(Presentation).defineSkin('bob', ['default'])
- zapi.getGlobalService(Presentation).setDefaultSkin('bob')
- self.assertEqual(self._service.defaultSkin, 'bob')
-
- def test_querySkin(self):
- # We don't let people define skins locally yet.
- # So just test that we can get the defs from the global service
- globalService = zapi.getGlobalService(Presentation)
- globalService.defineLayer('bob')
- globalService.defineSkin('bob', ['bob', 'default'])
- self.assertEqual(self._service.querySkin('bob'), ('bob', 'default'))
-
- def test_queryLayer(self):
- # We don't let people define layers locally yet.
- # So just test that we can get the them from the global service
- globalService = zapi.getGlobalService(Presentation)
- layer = self._service.queryLayer('default')
- self.assertEqual(layer.__parent__, globalService)
- self.test_queryView()
- layer = self._service.queryLayer('default')
- self.assertEqual(layer.__parent__, self._service)
-
- def test_queryDefaultViewName(self):
- # We don't let people define the default view name locally
- # yet. So just test that we can get it from the global
- # service
- class O(object):
- implements(I1)
- o = O()
- r = TestRequest()
- self.assertEqual(self._service.queryDefaultViewName(o, r),
- None)
- globalService = zapi.getGlobalService(Presentation)
- globalService.setDefaultViewName(I1, IBrowserRequest, 'foo.html')
- self.assertEqual(self._service.queryDefaultViewName(o, r),
- 'foo.html')
-
- def test_queryMultiView(self):
- # We don't let people define multiviews locally yet.
- # So just test that we can get them from the global service
- class X(object):
- implements(I1)
- class Y(object):
- implements(I3)
- x = X()
- y = Y()
- r = TestRequest()
- self.assertEqual(self._service.queryMultiView((x, y), r,
- name='foo.html'),
- None)
- globalService = zapi.getGlobalService(Presentation)
-
- class MV(object):
- def __init__(self, x, y, request):
- self.x, self.y, self.request = x, y, request
-
- globalService.provideAdapter(IBrowserRequest, MV, 'foo.html',
- contexts=(I1, I3))
- v = self._service.queryMultiView((x, y), r, name='foo.html')
- self.assertEqual(v.__class__, MV)
- self.assertEqual(v.request, r)
- self.assertEqual(v.x, x)
- self.assertEqual(v.y, y)
-
-
- def test_queryResource(self):
- # We don't let people define resources locally yet.
- # So just test that we can get them from the global service
-
- r = TestRequest()
- self.assertEqual(self._service.queryResource('logo.gif', r),
- None)
-
- class Resource(object):
- def __init__(self, request):
- self.request = request
-
- globalService = zapi.getGlobalService(Presentation)
- globalService.provideResource('logo.gif', IBrowserRequest, Resource)
-
- resource = self._service.queryResource('logo.gif', r)
- self.assertEqual(resource.__class__, Resource)
- self.assertEqual(resource.request, r)
-
- def test_implements_IPresentationService(self):
- from zope.component.interfaces import IPresentationService
-
- verifyObject(IPresentationService, self._service)
-
- def createTestingRegistry(self):
- return contained(LocalPresentationService(), C())
-
- def createTestingRegistration(self):
- return Registration()
-
- def test_implements_IPresentationService(self):
- verifyObject(IPresentationService, LocalPresentationService())
-
- def test_queryView_no_view(self):
- service = self._service
- class O(object):
- implements(I1)
-
- o = O()
- request = TestRequest()
- self.assertEqual(service.queryView(o, 'test', request), None)
- self.assertEqual(service.queryView(o, 'test', request, default=42), 42)
-
- def test_queryView(self):
- sm = traverse(self.rootFolder, '++etc++site')
-
- registration_manager = traverse(sm, 'default').getRegistrationManager()
- key = registration_manager.addRegistration(Registration())
- registration = traverse(registration_manager, key)
-
- class O(object):
- implements(I1)
-
- registration.factory = A
-
- registry = self._service.createRegistrationsFor(registration)
- registry.register(registration)
- registry.activate(registration)
-
- o = O()
- request = TestRequest()
-
- for r in I1, I1E:
- o = O()
- directlyProvides(o, r)
-
- view = self._service.queryView(o, 'test', request)
- self.assertEqual(view.__class__, A)
- self.assertEqual(view.context, o)
- self.assertEqual(view.request, request)
-
- def test_queryView_delegation(self):
- service = self._service
-
- sm = self.buildFolders(site=True)
- registration_manager = traverse(sm, 'default').getRegistrationManager()
- registration = Registration()
- name = registration_manager.addRegistration(registration)
- registration = traverse(registration_manager, name)
-
- class O(object):
- implements(I1)
-
- o = O()
- request = TestRequest()
-
- class A2(A): pass
-
- ztapi.browserView(I1, 'test', A2)
-
- view = service.queryView(o, 'test', request)
- self.assertEqual(view.__class__, A2)
- self.assertEqual(view.context, o)
- self.assertEqual(view.request, request)
-
- def test_registrations(self):
- self.test_queryView()
- registrations = map(str, self._service.registrations())
- registrations.sort()
- self.assertEqual(
- registrations,
-
- ['Registration(A)',
-
- # These were set up by PlacefulSetup:
- "zope.component.presentation.PresentationRegistration("
- "default, ('IContainmentRoot', 'IBrowserRequest'), "
- "'Interface', 'absolute_url', 'SiteAbsoluteURL', '')",
- "zope.component.presentation.PresentationRegistration("
- "default, (None, 'IBrowserRequest'), 'IAbsoluteURL', "
- "'', 'AbsoluteURL', '')",
- "zope.component.presentation.PresentationRegistration("
- "default, (None, 'IBrowserRequest'), 'Interface', "
- "'absolute_url', 'AbsoluteURL', '')",
- "zope.component.presentation.PresentationRegistration("
- "default, (None, None), "
- "'ITraversable', 'etc', 'etc', '')",
- ]
- )
-
- def test_localOnly_registrations(self):
- self.test_queryView()
- registrations = map(str, self._service.registrations(localOnly=True))
- registrations.sort()
- self.assertEqual(registrations, ['Registration(A)'])
-
- def test_getRegistrationsForInterface(self):
- self.test_queryView()
- for reg in self._service.getRegistrationsForInterface(I1):
- if reg.required is None:
- continue
- self.assertEqual(reg.required, I1)
-
- for reg in self._service.getRegistrationsForInterface(I1E):
- if reg.required is None:
- continue
- self.assertEqual(reg.required, I1)
-
-
class PhonyServiceManager(ServiceManager):
implements(IServiceService)
@@ -497,7 +281,6 @@
def test_suite():
return TestSuite([
- makeSuite(TestLocalPresentationService),
makeSuite(TestViewRegistration),
makeSuite(TestPageRegistration),
])
More information about the Zope3-Checkins
mailing list