[Zope3-Users] zope 3 book messageboard example..

Alec Flett alecf at flett.org
Thu Mar 30 13:16:28 EST 2006


Hey...
So I'm VERY new to Zope (2 days of hacking here and there) and going
through the Zope 3 Book and trying the "messageboard" example but I've
started getting an error that I just can't work out. For anyone familiar
with the examples I'm trying to make the recursive view of the messages
in a thread. I seem to be having some trouble with the recursion and
ViewPageTemplateFile - its like somehow Zope can't pass a dictionary
generated from a view onto a method within that view... I'm familiar
with the basic concepts of adaption and such but I can't for the life of
me figure out whats going on...

Here's the top of the stack and some of the sample code
----------
  File "C:\Python24\Lib\site-packages\zope\tales\expressions.py", line
205, in _
_call__
    return self._eval(econtext)
  File "C:\Python24\Lib\site-packages\zope\tales\expressions.py", line
192, in _
eval
    ob = self._subexprs[-1](econtext)
  File "C:\Python24\Lib\site-packages\zope\tales\expressions.py", line
124, in _
eval
    ob = self._traverser(ob, element, econtext)
  File "C:\Python24\Lib\site-packages\zope\app\pagetemplate\engine.py",
line 72,
in trustedZopeTraverser
    request=getattr(econtext, 'request', None))
  File "C:\Python24\Lib\site-packages\zope\app\traversing\adapters.py",
line 124
, in traverse
    curr = traversePathElement(curr, name, path, request=request)
  File "C:\Python24\Lib\site-packages\zope\app\traversing\adapters.py",
line 177
, in traversePathElement
    return traversable.traverse(nm, further_path)
  File "C:\Python24\Lib\site-packages\zope\app\traversing\adapters.py",
line 61,
in traverse
    raise TraversalError(subject, name)
TraversalError: (<zope.app.pagetemplate.viewpagetemplatefile.ViewMapper
object a
t 0x025E7110>, 'subthread')
------------
My thread.pt looks like this:
<html metal:use-macro="views/standard_macros/view">
  <body>
    <div metal:fill-slot="body">
      <h1>Discussion Thread</h1>

      <p>Thread goes here.</p>
      <div tal:replace="structure views/subthread"></div>
    </div>
  </body>
</html>
---------------
My thread.py looks like this (.thread.Thread is the class handling the view)

class Thread:

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

    def listContentInfo(self):
        children = []

        for name,child in self.context.items():
            if IMessage.providedBy(child):
                info = {}
                info['title'] = child.title

                url = self.base_url + name + '/'
                info['url'] = url + '@@thread.html'

                thread=Thread(child, self.request, url)
                info['thread'] = thread.subthread()

                children.append(info)

        return children

    subthread = ViewPageTemplateFile('subthread.pt')
----------

and subthread.pt looks like this:
<ul>
  <li tal:repeat="item view/listContentInfo">
    <a href=""
       tal:attributes="href item/url"
       tal:content="item/title">Message Title Here</a>
    <div tal:replace="structure item/thread"/>
  </li>
</ul>


So everything looks right to me - I wish I could offer more! I consider
myself a reasonably skilled Python developer but this is my first foray
into Zope

Alec



More information about the Zope3-users mailing list