[Zope] chain menu
Nico de Boer
nico@nfg.nl
31 May 2002 15:55:07 +0200
Hello,
I'm working on a chain menu which displays the following:
Previous | Current objectid | Next
Previous and Next are hyperlinks. When I have peer objects
(brothers and sisters) it is working fine. But when I have
no peers, I get the following error:
File /usr/lib/zope/lib/python/Products/PageTemplates/ZRPythonExpr.py, line 49, in __call__
(Info: chain[0])
File Python expression "chain[0]", line 2, in f
File /usr/lib/zope/lib/python/AccessControl/ZopeGuards.py, line 90, in guarded_getitem
TALESError: Sorry, an error occurred
This is my code (from a Zope Page Template): (thanks David)
<span tal:define="chain here/list_chain">
<a href="#" tal:condition="python:chain[0]" tal:attributes="href python:chain[0].absolute_url()">Previous</a>
<b tal:content="python:chain[1].title_or_id()">Sample title</b>
<a href="#" tal:condition="python:chain[2]" tal:attributes="href python:chain[2].absolute_url()">Next</a>
</span>
This is the list_chain method that I call in the above ZPTemplate:
def list_chain(self, sortkey='id'):
"""return (previous,current,next) objects """
NewsTuples = [] # a list of (sortkeyvalue,object) tuples
for item in self.REQUEST['PARENTS'][1].objectValues('News'):
if item.inDateRange():
NewsTuples.append(
(getattr(item,sortkey),item)
)
NewsTuples.sort()
(previous,current,next)=(None,None,None)
for (sortkey,object) in NewsTuples:
if current is not None:
return(previous,current,object)
elif object.id == self.id:
current=object
else:
previous=object
if previous is not None:
return(previous,current,next)
Can someone help me with this problem?
Greetz Nico