espenmn
(Espen)
October 5, 2020, 10:16am
1
I have always used:
def something():
return "something"
and ${view/something) in template.pt
Using bob templates (plonecli) to add a browser view it adds a
def __call__(self):
# Implement your own actions:
self.msg = _(u'A small message')
Is this approache "better" (faster?) than the other ?
jensens
(Jens W. Klein)
October 5, 2020, 12:44pm
2
It does not really matter. I prefer methods (or @property
decorated methods) as well. If you want to have it faster:
use ${python:view.something()}
since TALES has some significant overhead.
1 Like
alert
(Alessandro Pisa)
October 5, 2020, 1:52pm
4
In this particular case:
class View(...):
msg = _(u'A small message')
is good as well.
But I agree with @jensens , property are IMO better than defining an instance variable.
Unless you add a property setter, properties cannot be changed and tracking changed instance variable in the code is a major pain.
1 Like