Skip to content

Commit

Permalink
Fix up zope.app for new location of zope.traversing.
Browse files Browse the repository at this point in the history
(also sneaked in some minor cosmetics regarding zapi/ztapi)
  • Loading branch information
philikon committed Apr 5, 2006
1 parent e90eb00 commit 86e7a4a
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 12 deletions.
63 changes: 63 additions & 0 deletions browser/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<zope:configure
xmlns:zope="http://namespaces.zope.org/zope"
xmlns="http://namespaces.zope.org/browser">

<tool
interface="zope.app.schema.interfaces.ISchemaUtility"
title="Persistent, Local Schemas"
description="These are schemas that live in the ZODB and are modifiable."
/>

<menu
id="add_schema_field"
title="Menu of Fields to be added to a schema." />

<view
name="+"
for="zope.app.schema.interfaces.IMutableSchema"
class="zope.app.schema.schema.SchemaAdding"
permission="zope.ManageContent"
allowed_attributes="addingInfo"
menu="zmi_actions" title="Add">

<page name="index.html" template="schema_add.pt" />
<page name="action.html" attribute="action" />

</view>

<addMenuItem
title="Mutable Schema"
description="A Persistent Schema that can be edited through the web"
class="zope.app.schema.schema.SchemaUtility"
permission="zope.ManageServices"
/>

<defaultView
for="zope.app.schema.interfaces.IMutableSchema"
name="editschema.html" />

<page
name="editschema.html"
menu="zmi_views" title="Edit Schema"
for="zope.app.schema.interfaces.IMutableSchema"
permission="zope.ManageServices"
class=".EditSchema"
attribute="edit"
/>

<!-- Register a browser-specific traverser -->

<zope:view
for="zope.app.schema.interfaces.IMutableSchema"
type="zope.publisher.interfaces.browser.IBrowserRequest"
provides="zope.publisher.interfaces.browser.IBrowserPublisher"
factory=".traversal.SchemaFieldTraverser"
permission="zope.Public"
/>

<zope:adapter
factory=".traversal.SchemaFieldTraversable"
provides="zope.traversing.interfaces.ITraversable"
for="zope.app.schema.interfaces.IMutableSchema" />

</zope:configure>
74 changes: 74 additions & 0 deletions browser/traversal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
##############################################################################
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
##############################################################################
"""Specific HTTP Traverser
$Id$
"""
from zope.interface import implements
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces import NotFound
from zope.traversing.interfaces import TraversalError, ITraversable
from zope.traversing.namespace import UnexpectedParameters

from zope.app import zapi
from zope.app.location.interfaces import ILocation
from zope.app.schema.interfaces import IMutableSchema

_marker = object()

class SchemaFieldTraverser(object):
implements(IBrowserPublisher)
__used_for__ = IMutableSchema

def __init__(self, context, request):
self.context = context
self.request = request

def publishTraverse(self, request, name):
subob = self.context.get(name, None)

if subob is None:

view = zapi.queryMultiAdapter((self.context, request), name=name)
if view is not None:
if ILocation.providedBy(view):
view.__parent__ = self.context
view.__name__ = name

return view

raise NotFound(self.context, name, request)

return subob

def browserDefault(self, request):
c = self.context
view_name = zapi.getDefaultViewName(c, request)
view_uri = "@@%s" % view_name
return c, (view_uri,)

class SchemaFieldTraversable(object):
"""Traverses Schema Fields.
"""

implements(ITraversable)
__used_for__ = IMutableSchema

def __init__(self, context):
self._context = context

def traverse(self, name, furtherPath):
subobj = self._context.get(name, _marker)
if subobj is _marker:
raise TraversalError(name)

return subobj
24 changes: 12 additions & 12 deletions tests/test_interfaceutility.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
$Id$
"""
import unittest
import zope.component
from zope.interface import Interface, implements
from zope.interface.interface import InterfaceClass
from zope.interface.interfaces import IInterface
from zope.component.interfaces import ComponentLookupError
from zope.traversing.api import traverse

from zope.app import zapi
from zope.app.component.interfaces import ILocalUtility
from zope.app.component.testing import PlacefulSetup
from zope.app.component.interface import getInterface, searchInterface
Expand All @@ -31,7 +32,6 @@
from zope.app.container.contained import Contained
from zope.app.dependable.interfaces import IDependable
from zope.app.testing import setup
from zope.app.traversing.api import traverse

class IBaz(Interface): pass

Expand Down Expand Up @@ -88,7 +88,7 @@ def setUp(self):
sm = PlacefulSetup.setUp(self, site=True)

def test_getLocalInterface_delegates_to_globalUtility(self):
gsm = zapi.getGlobalSiteManager()
gsm = zope.component.getGlobalSiteManager()
gsm.registerUtility(Bar("blob"), IInterface, name="blob")
gsm.registerUtility(Baz("global baz"), IBaz)
gsm.registerUtility(Foo("global bob"), IInterface, name="bob")
Expand All @@ -101,7 +101,7 @@ def test_localInterfaceitems_filters_accordingly(self):
baz = Baz("global baz")
foo = Foo("global bob")

gsm = zapi.getGlobalSiteManager()
gsm = zope.component.getGlobalSiteManager()
gsm.registerUtility(foo, IInterface, name="bob")
gsm.registerUtility(bar, IInterface)
gsm.registerUtility(baz, IBaz)
Expand All @@ -125,7 +125,7 @@ def test_localInterfaceitems_filters_only_interfaces(self):
bar = Bar("global")
baz = Baz("global baz")
foo = Foo("global bob")
gsm = zapi.getGlobalSiteManager()
gsm = zope.component.getGlobalSiteManager()

gsm.registerUtility(foo, IInterface, name="bob")
gsm.registerUtility(bar, ILocalUtility)
Expand All @@ -144,7 +144,7 @@ def test_localInterfaceitems_filters_only_interfaces(self):
self.assertEqual(ifaces, [(baz)])

def test_getLocalInterface_raisesComponentLookupError(self):
gsm = zapi.getGlobalSiteManager()
gsm = zope.component.getGlobalSiteManager()
gsm.registerUtility(Foo("global"), Interface)
gsm.registerUtility(Baz("global baz"), IBaz)
gsm.registerUtility(Foo("global bob"), IInterface, name="bob")
Expand All @@ -156,7 +156,7 @@ def test_globalsearchInterface_delegates_to_globalUtility(self):
foo = Foo("global bob")
bar = Bar("global")
baz = Baz("global baz")
gsm = zapi.getGlobalSiteManager()
gsm = zope.component.getGlobalSiteManager()
gsm.registerUtility(foo, IInterface, name="bob")
gsm.registerUtility(bar, IInterface)
gsm.registerUtility(baz, IBaz)
Expand All @@ -169,7 +169,7 @@ def test_localsearchInterface_delegates_to_globalUtility(self):
foo = Foo("global bob")
bar = Bar("global")
baz = Baz("global baz")
gsm = zapi.getGlobalSiteManager()
gsm = zope.component.getGlobalSiteManager()
gsm.registerUtility(foo, IInterface, name="bob")
gsm.registerUtility(bar, IInterface)
gsm.registerUtility(baz, IBaz)
Expand All @@ -178,11 +178,11 @@ def test_localsearchInterface_delegates_to_globalUtility(self):
[foo])

def test_query_get_Utility_delegates_to_global(self):
gsm = zapi.getGlobalSiteManager()
gsm = zope.component.getGlobalSiteManager()
gsm.provideUtility(IInterface, Foo("global"))
gsm.provideUtility(IInterface, Foo("global bob"), name="bob")

sm = zapi.getSiteManager(self.rootFolder)
sm = zope.component.getSiteManager(self.rootFolder)
self.assert_(gsm != sm)

# If queryUtility works on the site manager, getUtility in zapi must
Expand All @@ -192,11 +192,11 @@ def test_query_get_Utility_delegates_to_global(self):
"foo global bob")

def test_local_utilities(self):
gsm = zapi.getGlobalSiteManager()
gsm = zope.component.getGlobalSiteManager()
gsm.registerUtility(Foo("global"), IInterface)
gsm.registerUtility(Foo("global bob"), IInterface, name="bob")

sm = zapi.getSiteManager(self.rootFolder)
sm = zope.component.getSiteManager(self.rootFolder)
default = traverse(self.rootFolder, "++etc++site/default")
default['foo'] = Foo("local")
foo = default['foo']
Expand Down

0 comments on commit 86e7a4a

Please sign in to comment.