Skip to content
This repository has been archived by the owner on Dec 17, 2020. It is now read-only.

Commit

Permalink
Fix some issue with ITreeItems adapter and add an additional
Browse files Browse the repository at this point in the history
discriminator which prevents to load this adapter instead of the @@ view.
This is a workaround needed because of the base registry we use.
  • Loading branch information
projekt01 committed Apr 14, 2008
1 parent 96ea2bb commit 4ce449c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/z3c/jsontree/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def id(self):
return self.getId(self.context)


class TreeBase(subitem.SubItemMixin):
class TreeBase(subitem.SubItemAware):
"""Tree iterator base implementation."""

root = None
Expand Down Expand Up @@ -225,14 +225,13 @@ def toggleIcon(self):
icon.height, longDescURL))

def icon(self):
"""Returns a toggle icon including settings for json url."""
"""Returns a additional named icon for the given context."""
icon = zope.component.queryMultiAdapter((self.context, self.request),
name=self.iconName)
if icon is not None:
resource = getResource(icon.context, icon.rname, self.request)
src = resource()
longDescURL = absoluteURL(self.context, self.request)
return ('<img src="%s" alt="toggle icon" width="%s" height="%s" '
return ('<img src="%s" alt="icon" width="%s" height="%s" '
'border="0" />' % (src, icon.width, icon.height))
return u''

Expand Down
4 changes: 2 additions & 2 deletions src/z3c/jsontree/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<z3c:template
template="li.pt"
for="z3c.jsontree.interfaces.ILITagProvider"
layer="zope.publisher.interfaces.browser.IBrowserRequest"
layer="zope.publisher.interfaces.http.IHTTPRequest"
/>

<zope:adapter
Expand All @@ -32,7 +32,7 @@
<z3c:template
template="ul.pt"
for="z3c.jsontree.interfaces.IULTagProvider"
layer="zope.publisher.interfaces.browser.IBrowserRequest"
layer="zope.publisher.interfaces.http.IHTTPRequest"
/>

<resourceDirectory
Expand Down
12 changes: 8 additions & 4 deletions src/z3c/jsontree/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@

<adapter
for="zope.interface.Interface
zope.publisher.interfaces.browser.IBrowserRequest"
zope.publisher.interfaces.browser.IBrowserRequest
z3c.jsontree.interfaces.ISubItemAware"
factory=".subitem.NoneTreeItems"
/>

<adapter
for="zope.app.container.interfaces.IReadContainer
zope.publisher.interfaces.browser.IBrowserRequest"
zope.publisher.interfaces.browser.IBrowserRequest
z3c.jsontree.interfaces.ISubItemAware"
factory=".subitem.ContainerTreeItems"
/>

<adapter
for="zope.interface.Interface
z3c.jsonrpc.interfaces.IJSONRPCRequest"
z3c.jsonrpc.interfaces.IJSONRPCRequest
z3c.jsontree.interfaces.ISubItemAware"
factory=".subitem.NoneTreeItems"
/>

<adapter
for="zope.app.container.interfaces.IReadContainer
z3c.jsonrpc.interfaces.IJSONRPCRequest"
z3c.jsonrpc.interfaces.IJSONRPCRequest
z3c.jsontree.interfaces.ISubItemAware"
factory=".subitem.ContainerTreeItems"
/>

Expand Down
6 changes: 5 additions & 1 deletion src/z3c/jsontree/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@
STATE_STATIC = 'static'


class ISubItemAware(zope.interface.Interface):
"""Sub item aware object."""


class ITreeItems(zope.interface.Interface):
"""Knows the items listed in tree for the given context."""

def __init__(context, provider):
def __init__(context, request, tree):
"""Adapts the context and the request.
This allows to use different adapters for different layers on the same
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/jsontree/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def loadJSONTreeItems(self, id):
return {'treeChilds': {'id':id, 'childs':[]}}


class JSONTreeItems(subitem.SubItemMixin, MethodPublisher,
class JSONTreeItems(subitem.SubItemAware, MethodPublisher,
base.IdGenerator):
"""Returns the data of the childs from the path for the json tree.
Expand Down
9 changes: 6 additions & 3 deletions src/z3c/jsontree/subitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
_ = zope.i18nmessageid.MessageFactory('z3c')


class SubItemMixin(object):
class SubItemAware(object):
"""Base class for sub item lookup."""

zope.interface.implements(interfaces.ISubItemAware)

def getSubItems(self, item):
"""Delegate call to ITreeItems adapter."""
adapter = zope.component.getMultiAdapter((item, self.request),
adapter = zope.component.getMultiAdapter((item, self.request, self),
interfaces.ITreeItems)
return adapter.subItems

Expand All @@ -45,9 +47,10 @@ class TreeItemsMixin(object):

zope.interface.implements(interfaces.ITreeItems)

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


class NoneTreeItems(TreeItemsMixin):
Expand Down

0 comments on commit 4ce449c

Please sign in to comment.