Maurits van Rees, on 2008-01-14:
> Dieter Maurer, on 2008-01-14:
>> Maurits van Rees wrote at 2008-1-13 23:32 +0000:
>>>I have some code where I try to get a named template and render it and
>>>if it fails I render a default template instead. But this fails,
>>>presumably because the __call__ method of NamedTemplate does not
>>>return anything. From zope/formlib/namedtemplate.py (Zope 2.10):
>>> def __init__(self, name):
>>> self.__name__ = name
>>> def __get__(self, instance, type=None):
>>> if instance is None:
>>> return self
>>> return component.getAdapter(instance, INamedTemplate, self.__name__)
>>> def __call__(self, instance, *args, **kw):
>>> self.__get__(instance)(*args, **kw)
>>>I seems strange to me that __call__ does not actually return
>>>anything. Is it just me?
>> It returns only if you use "return" (otherwise, it returns "None").
>> Thus, try "return self.__get__(....)".
> I know. :) I think you misunderstood me there. This class is from
> core Zope (zope.formlib.namedtemplate). So to refrase my question:
> why does this call method not do "return self.__get(....)"? Looks
> like a bug to me, but this line has been there since 2005 and named
> templates do seem to work fine, so I am confused.
Actually, when I remove that __call__ method from namedtemplate.py,
the zope.formlib tests still pass (and in fact all 5868 tests from
bin/test.py pass). Tested on the Zope 2.10 branch.
So I would say: either the call method should be fixed by making it
return the value it has just calculated, or it should be removed.
When I remove the call method, my own code sill throws an error, a
different one now:
AttributeError: NamedTemplateImplementation instance has no __call__ method
For a minute I thought I could work around that by directly using the
only line from the above class that I really need:
template = getAdapter(self, INamedTemplate, 'myname')
But that still throws the same AttributeError.
I must be doing something strange...
Maurits van Rees | http://maurits.vanrees.org/
Work | http://zestsoftware.nl/
"This is your day, don't let them take it away." [Barlow Girl]
Zope maillist - Zope@zope.org
** No cross posts or HTML encoding! **
(Related lists -