Re: [Zope3-dev] views have no __page_attribute__ ?
Jean-Marc Orliaguet wrote: Hi! I've encountered a problem when trying to render views (there is no problem with rendering pages), but for instance with the '+' view that is defined in app/container/browser/configure.zcml view for=zope.app.container.interfaces.IContentContainer name=+ menu=zmi_actions title=Add class=zope.app.container.browser.adding.ContentAdding permission=zope.ManageContent allowed_attributes=addingInfo isSingleMenuItem hasCustomAddView page name=index.html template=add.pt / page name=action.html attribute=action / /view when called with: markup = view() ['view' being the 'view' variable gotten from ZPT) results in the following error message: ... markup = view() File /home/jmo/Zope3/src/zope/app/publisher/browser/viewmeta.py, line 445, in __call__ attr = self.__page_attribute__ AttributeError: '+' object has no attribute '__page_attribute__' because the __call__ method of zope.app.publisher.browser.viewmeta.simple expects views and pages to have a page attribute: def __call__(self, *a, **k): # If a class doesn't provide it's own call, then get the attribute # given by the browser default. attr = self.__page_attribute__ With the '+' view described above, there is a default page attribute to use for displaying the view ('index.html') and but no page attribute explicitly assigned. The following patch fixes the problem, but I'm afraid that I'm missing something: are views supposed to have a '__page_attribute__' or not? They are only supposed to ave a page attribute if they are pages. :) The directive above creates a view *with pages*. This means that the view itself should not a page and is not intended to be callable. Bottom line: views created this way are not callable and are not directly renderable. There's a bit more complexity than I'd like in these view directives. This is why, more and more, I tend to *define* views in Python and just register them with the adapter or view directive. I still do often find it useful to register views with the view directive, mainly so I can avoid having to mention IBrowserRequest. Jim -- Jim Fulton mailto:[EMAIL PROTECTED] Python Powered! CTO (540) 361-1714http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] views have no __page_attribute__ ?
Jean-Marc Orliaguet wrote: Jim Fulton wrote: Jean-Marc Orliaguet wrote: ... With the '+' view described above, there is a default page attribute to use for displaying the view ('index.html') and but no page attribute explicitly assigned. The following patch fixes the problem, but I'm afraid that I'm missing something: are views supposed to have a '__page_attribute__' or not? They are only supposed to ave a page attribute if they are pages. :) The directive above creates a view *with pages*. This means that the view itself should not a page and is not intended to be callable. Bottom line: views created this way are not callable and are not directly renderable. There's a bit more complexity than I'd like in these view directives. This is why, more and more, I tend to *define* views in Python and just register them with the adapter or view directive. I still do often find it useful to register views with the view directive, mainly so I can avoid having to mention IBrowserRequest. Jim OK, so the 'view' object set in page templates is not the object to call for rendering the page. Uh, normally the page template renders the page. Different views are constructed differently. Views created with the page directive and views created with a view directive without page subdirectives *can* be called to render pages -- basically because they *are* pages. OTOH a view directive with page subdirectives is meant to be traversed to get to it's pages, which then can be called. All in all, I managed to render the '+' view by calling the 'template' object and passing the 'view' as the instance parameter markup = template(instance=view) I'm confused. Aren't you already in the template? Jim -- Jim Fulton mailto:[EMAIL PROTECTED] Python Powered! CTO (540) 361-1714http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] views have no __page_attribute__ ?
Jim Fulton wrote: Jean-Marc Orliaguet wrote: Jim Fulton wrote: Jean-Marc Orliaguet wrote: ... With the '+' view described above, there is a default page attribute to use for displaying the view ('index.html') and but no page attribute explicitly assigned. The following patch fixes the problem, but I'm afraid that I'm missing something: are views supposed to have a '__page_attribute__' or not? They are only supposed to ave a page attribute if they are pages. :) The directive above creates a view *with pages*. This means that the view itself should not a page and is not intended to be callable. Bottom line: views created this way are not callable and are not directly renderable. There's a bit more complexity than I'd like in these view directives. This is why, more and more, I tend to *define* views in Python and just register them with the adapter or view directive. I still do often find it useful to register views with the view directive, mainly so I can avoid having to mention IBrowserRequest. Jim OK, so the 'view' object set in page templates is not the object to call for rendering the page. Uh, normally the page template renders the page. Different views are constructed differently. Views created with the page directive and views created with a view directive without page subdirectives *can* be called to render pages -- basically because they *are* pages. OTOH a view directive with page subdirectives is meant to be traversed to get to it's pages, which then can be called. All in all, I managed to render the '+' view by calling the 'template' object and passing the 'view' as the instance parameter markup = template(instance=view) I'm confused. Aren't you already in the template? Jim well sort of: I do start from a standard template (the original browser/skin/template.pt) that contains the macro -page definition, the head markup, and the actual call to the theme renderer in the body part of the template. metal:block define-macro=page metal:block define-slot=doctype html headCSS / JS comes here/head body tal:content=python: theme.render(...) / /html then I pass the: - context - view - template to theme.render(...) then the renderer in python takes care of rendering for the main content area that would have been displayed otherwise. So I have to re-render the page in its original context. It works apparently with: template(instance=view) .. /JM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com