[Zope] creating objects in dtml?

Dylan Reinhardt zope at dylanreinhardt.com
Mon Oct 20 12:46:56 EDT 2003


On Mon, 2003-10-20 at 08:50, Ted holden wrote:
> I have a python class which I've set up as a zope product and which shows up 
> as such.

Super.

> 
> Now, products installed this way don't show up on menus, so I've more or less 
> followed the instructions and created a product with a zclass which 
> subclasses the installed python product and, sure enough, this zclass shows 
> up on menus.

That shouldn't be necessary... did you register the class correctly in
your product's __init__ module?

> 
> The next step was to create a folder with a dtml  page and an instance of the 
> zclass in it, and use the instance of the zclass in the dtml page, and that 
> works.

If it works, I suppose that's something... but if you can do it all in
your external product code, you might get better results & easier
maintainability.

> 
> Nonetheless, ultimately, that doesn't seem to be what I want.  Unless I'm 
> missing something, that creates a single instance (object) of the class for 
> good and all. 

Yep.

>  I see print statements from the constructor the first time I 
> ever bring the page up;  afterwards, the object is still there, but it isn't 
> being created.  The systems seems to be saving it.

Correct... because you've created a persistent object, it is being
persisted.

> 
> What I really need is for a user to open a dtml page and create (his/her) 
> object in doing so, and then use it.  

That's certainly possible... but then what?  You want this object to
only exist during the time the user has a session?

To answer the first part, the URL to create a new instance of a product
is usually something of the form:

container/manage_addProduct/product_name/product_nameAdd

As for collecting unused objects, you'll probably want to create a
python script that steps over the instances of your product and deletes
those that are deemed expired (however you choose to determine that). 
Then call that script from a cron job or something that can fire it off
regularly.

With a system that's adding and deleting instances with any regularity,
you'll want to be sure to have a cron job pack your database regularly
too.

HTH,

Dylan





More information about the Zope mailing list