[Zope3-dev] RE: [Zope3-Users] page uses foreignview:contextchanged

Florian Lindner mailinglists at xgm.de
Fri Apr 15 12:42:49 EDT 2005


Am Mittwoch, 13. April 2005 16:16 schrieb Roger Ineichen:

> > One more question: How can I use only a specific macro of the view?
>
> try this:
>
> def __init__(self, context, request):
>   self.context = context
>   self.request = request
>
> def getMacro(self):
>
>   macrocode = ""
>   # get the childs of folder 'f'
>   childs = self.context.values()
>
>   for item in childs:
>
>     # get the 'childView' for each item
>     view = zapi.getMultiAdapter((self.context, item), name='childView')
>
>     # call the view, this returns the html code of the view
>     macrocode += view.index['mymacroname']
>
>     # return all html code where get collected
>     return macrocode
>
> The result of getMacro can be used in the folder view like:
>
> <tal:block metal:use-macro="context/getMacro" />
>
>
> btw; don't use getView(), use getMultiAdapter().
>
> The method getView is deprecated and you should seee a TraceBack
> if you use getView()!

Here it does not really work. When I'm using this code:

        childs = homefolder.values()
        
        for item in childs:
            print item.__name__
            view = getMultiAdapter((self.context, item), name="childInfo") <--
    
            htmlcode += view.index["childInfo"]
    
        return htmlcode

I get the following traceback:

File "/home/florian/Zope3/src/zope/component/__init__.py", line 154, in 
getMultiAdapter
    raise ComponentLookupError(objects, interface, name)
ComponentLookupError: ((<CS.centershock.centershock.Centershock object at 
0xb76342ec>, <CS.Linklist.link.Link object at 0xb67ba38c>), <InterfaceClass 
zope.interface.Interface>, 'childInfo')


childInfo is registered in the configure.zcml of the Link object:

    <page
        name="childInfo"
        for="CS.Linklist.interfaces.ILink"
        template="childInfo.pt"
        permission="zope.View"
        layer="centershock"
    /> 

When I change the code to use the deprecated getView method:

        childs = homefolder.values()
        
        for item in childs:
            print item.__name__
            view = getView(item, "childInfo", self.request)
    
            htmlcode += view.index["childInfo"] <--
    
        return htmlcode

I get a traceback one instruction later:

  File 
"/home/florian/Desktop/zope/lib/python/CS/centershock/browser/skin/views.py", 
line 41, in getHTML
    htmlcode += view.index["childInfo"]
TypeError: unsubscriptable object

Altough the childInfo.py contains the macro:

    <metal:block define-macro="childInfo">


Maybe it is a problem that self.context != homefolder?

Thx,

Florian

@Florent: You're perfectly right. Hope it's ok now. ;-)




More information about the Zope3-dev mailing list