__call__ folderish Zope objects

19 December 2004   0 comments   Zope

Mind That Age!

This blog post is 13 years old! Most likely, its content is outdated. Especially if it's technical.

Powered by Fusion×

I ran into trouble with a Zope class that inherits from OFS.Folder.Folder (the classic Folder class). My class is a bit special since it's acting both as a non-folderish document like object but still needs to contain other objects such as images and file attachments. The class had a method called index_html which looked something like this:

def index_html(self, REQUEST, **kw):
    """ return something"""
    return self.something

The problem was that if I create one of these instances with the id index_html it simply could not be viewed. What I had to do was to use the __call__() function on my class. That is apparently how Zope figures out which document to show/call. Now my class had this instead:

def __call__(self, REQUEST, **kw):
    """ wrap view() """
    return self.view(self.REQUEST, **kw)

def view(self, REQUEST, **kw):
    """ return something"""
    return self.something

That took care of my problems and now the parent instances could instantly view my document like instances called index_html.

So, for the next time; use __call__() instead of index_html().

Follow @peterbe on Twitter

Comments

Thank you for posting a comment

Your email will never ever be published


Related posts

Previous:
Ugliest site of the month, plus44.com 17 December 2004
Next:
The problem with CSS 21 December 2004
Related by Keyword:
TAL here hack in Plone 28 April 2005
Related by Text:
Newfound love of @staticmethod in Python 02 July 2012
Setting security declarations to Zope classes 02 February 2006
How to unit test the innards of a Django view function 15 November 2008
My dislike for booleans and that impact on the Django Admin 01 June 2009
When '_properties' gets stuck as a persistent attribute 01 October 2008