[Zope] Working with TransientObjectContainer
Gilberto Gil Pereira
ggsfp@students.fct.unl.pt
Thu, 27 Jun 2002 16:43:40 +0100 (WEST)
Thanks for your speedy answer Chris.
I found out what my mistake was. I was trying to call an add or del method
with my own arguments. Therefor Zope was calling that method and
executing it on the moment I place it as an argument.
Thanks also for your example. With a litle change were and there, it was
exactly what I was needing for.
With regards
Gil
On Thu, 27 Jun 2002, Chris McDonough wrote:
> Hi Gliberto,
>
> TransientObjectContainer's __init__ looks something like this:
>
> def __init__(self, id,
> title='',
> timeout_mins=20,
> addNotification=None,
> delNotification=None):
>
> For the "addNotification" and "delNotification" parameters you can pass
> in either a Zope object path (to a Python Script or External Method,
> generally) that refers to a callable object or a Python reference to a
> callable object. The callable object needs to accept two parameters:
> "item" and "container". At call time, "item" is the transient object
> being notified and "container" is the transient object container.
>
> The addNotification happens when an item is added to the container.
>
> The delNotification happens right before an item is removed from
> the container (usually as a result of the item expiring).
>
> So if you create your own TransientObjectContainer with add and delete
> notifiers, it might look something like this:
>
> def add(self, item, container):
> print "adding %s" % item
>
> def del(self, item, container):
> print "deleting %s" % item
>
> toc = TransientObjectContainer(id='toc', title='', timeout_mins=20,
> addNotification=add, delNotification=del)
>
>
> transient_object = toc.new_or_existing()
> ( will print "adding <TransientObject>")
> ... wait 20 minutes or so ...
> toc.nudge()
> ( might print "deleting <TransientObject>", but may require several nudges)
>
> HTH,
>
> - C
>
>