[Zope3-Users] Is a view persistent?

Fred Drake fdrake at gmail.com
Thu Aug 2 07:37:30 EDT 2007


On 8/2/07, Hermann Himmelbauer <dusty at qwer.tk> wrote:
>     mylist = []
>
>     @button.buttonAndHandler(_(u'Suchen'), name='suchen')
>     def handle_suchen(self, action):
>              self.mylist.append(123)
>
> When I output "mylist" in my page template, the number 123 is appended to
> mylist if I press the "Suchen" button, so if I press it 5 times, the list
> holds 5 items. When I restart my zope instance, the list is empty again.

The attribute will be "persistent" so long as you don't restart the
process, *because* it's a class attribute.  Note that the code you
showed never sets the value of self.mylist, but only mutates the
existing value.

To not have a semi-persistent self.mylist, do this instead:

    def handle_suchen(self, action):
             self.mylist = [123]


  -Fred

-- 
Fred L. Drake, Jr.    <fdrake at gmail.com>
"Chaos is the score upon which reality is written." --Henry Miller


More information about the Zope3-users mailing list