[Zope3-Users] Extending the Buddy demo -- adding BuddyFolder.hello() method how?

Adam Summers adam at 4js.com.au
Wed Dec 29 00:16:04 EST 2004


Hi,

    Thanks for your tip Dominik - I understand what you mean, however I 
still have a problem with calling the method in my BuddyFolder class:
My interface is:

    class IBuddyFolder(IContainer, IContentContainer):

    def __setitem__(name, object):
        """Add a buddy"""

    __setitem__.precondition = ItemTypePrecondition(IBuddy)

    def hello():
        """Return list of buddy names"""

My Implementation is:

    class BuddyFolder(BTreeContainer):
    zope.interface.implements(IBuddyFolder)

    __used_for__ = IBuddyFolder

    def hello(self):
        return "Hello World"

And my configuration is:
   
    <content class=".buddy.BuddyFolder">
        <require permission="zope.View"
            interface="zope.app.container.interfaces.IReadContainer" />
        <require permission="zope.ManageContent"
            interface="zope.app.container.interfaces.IWriteContainer" />
    </content>

    <browser:addMenuItem
        title="Buddy Folder"
        class=".buddy.BuddyFolder"
        permission="zope.ManageContent" />

    <browser:containerViews
        for=".interfaces.IBuddyFolder"
        contents="zope.ManageContent"
        index="zope.View"
        add="zope.ManageContent"
        />

    <browser:page
        for=".interfaces.IBuddyFolder"
        name="hello.html"
        template="hello.pt"
        permission="zope.ManageContent" />

However, when I use tal:content="context/hello" I get the following 
traceback below. Where am I going wrong??? I know I can do this by 
supplying a view to the model, but I really need to have this method in 
the model (it will be used for computing values pertinent to the data 
contained in the folder for example).

Many thanks for help thus far.
Adam


    2004-12-29T15:24:22 ERROR SiteError 
http://demo:8080/testF/nwF/hello.html
Traceback (most recent call last):
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/publisher/publish.
py", line 138, in publish
    result = publication.callObject(request, object)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/app/publication/zo
pepublication.py", line 153, in callObject
    return mapply(ob, request.getPositionalArguments(), request)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/publisher/publish.
py", line 113, in mapply
    return debug_call(object, args)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/publisher/publish.
py", line 119, in debug_call
    return object(*args)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/app/pagetemplate/s
impleviewclass.py", line 45, in __call__
    return self.index(*args, **kw)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/app/pagetemplate/v
iewpagetemplatefile.py", line 76, in __call__
    return self.im_func(im_self, *args, **kw)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/app/pagetemplate/v
iewpagetemplatefile.py", line 45, in __call__
    s = self.pt_render(namespace)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/pagetemplate/paget
emplate.py", line 118, in pt_render
    context, output, tal=not source, strictinsert=0)()
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 165, in __call__
    self.interpret(self.program)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 208, in interpret
    handlers[opcode](self, args)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 681, in do_useMacro
    self.interpret(macro)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 208, in interpret
    handlers[opcode](self, args)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 377, in do_optTag_tal
    self.do_optTag(stuff)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 362, in do_optTag
    return self.no_tag(start, program)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 357, in no_tag
    self.interpret(program)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 208, in interpret
    handlers[opcode](self, args)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 655, in do_defineMacro
    self.interpret(macro)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 208, in interpret
    handlers[opcode](self, args)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 714, in do_defineSlot
    self.interpret(block)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 208, in interpret
    handlers[opcode](self, args)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 706, in do_defineSlot
    self.interpret(slot)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 208, in interpret
    handlers[opcode](self, args)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tal/talinterpreter
.py", line 451, in do_insertText_tal
    text = self.engine.evaluateText(stuff[0])
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/app/pagetemplate/e
ngine.py", line 99, in evaluateText
    text = self.evaluate(expr)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tales/tales.py", l
ine 698, in evaluate
    return expression(self)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tales/expressions.
py", line 207, in __call__
    return self._eval(econtext)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tales/expressions.
py", line 194, in _eval
    ob = self._subexprs[-1](econtext)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/tales/expressions.
py", line 126, in _eval
    ob = self._traverser(ob, element, econtext)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/app/pagetemplate/e
ngine.py", line 70, in trustedZopeTraverser
    request=getattr(econtext, 'request', None))
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/app/traversing/ada
pters.py", line 114, in traverse
    curr = traversePathElement(curr, name, path, request=request)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/app/traversing/ada
pters.py", line 167, in traversePathElement
    next_item = traversable.traverse(nm, further_path)
  File 
"/home/adam/ZopeX3-3.0.0/build/lib.linux-i686-2.4/zope/app/container/trav
ersal.py", line 99, in traverse
    raise NotFoundError, name
NotFoundError: 'hello'
192.168.168.1 - zope.manager [29/Dec/2004:15:24:22 +1100] "GET 
/testF/nwF/hello.
html HTTP/1.1" 200 292 "" "Mozilla/5.0 (Windows; U; Windows NT 5.1; 
en-US; rv:1.
7.5) Gecko/20041107 Firefox/1.0"
                                  
   
Dominik Huber wrote:

> Adam Summers wrote:
>
>> <browser:page
>>     for=".interfaces.IBuddyFolder"
>>     name="hello.html"
>>     class=".buddy.BuddyFolder"
>>     template="hello.pt"
>>     permission="zope.ManageContent"
>>     />
>>
> try
>
> <browser:page
>    for=".interfaces.IBuddyFolder"
>    name="hello.html"
>    template="hello.pt"
>    permission="zope.ManageContent"
>    />
>
> the class attribute describes a 'view' class and not your 'model' 
> class. a view class is a multiadapter to the context (your buddyfolder 
> instance) and the request:
>
> class BuddyFolderView:
>
>   def __init__(self, context, request):
>       ....
>
> versus
>
> class BuddyFolder:
>   def __init__(self):
>      ...
>
> such a view class you are going to use  if your context (model) should 
> provide additional interfaces.
>
> regards,
> dominik






More information about the Zope3-users mailing list