Re: [Zope] Altering product instance changes all instances!
D'oh! This is actually a HOWTO that I meant to write 3 or 4 weeks ago. You can check out KM|Net News. My constructor clones DTML Methods (instead of Images), but it was pretty easy and works completely within DTML. I also added a "Defaults" tab so that you can easily plug the latest "default" version into an individual instance. Here is Albert Kinderman's summary of our discussion from October 1. [quote] In your xProduct, create a DTML document (or method) with id default. This is at the same level as the xClass, xClass_add, xClass_addForm, and xClassFactory. [NOTE: Kevin says to put the default in the xClass. Try it either way.] In your xClass_add, include within the <dtml-with "xClass.createInObjectManager(REQUEST['id'], REQUEST)"> the lines <dtml-call "REQUEST.set('data',default.document_src(REQUEST,RESPONSE))"> <dtml-call "manage_addDTMLDocument('default','',data)"> [changed in the obvious way for a DTML Method] along with any property sheet management call (as explained in the comment in the standard xClass_add). Now when you create an instance of x, the document default will be automatically created within the instance created. Since default is inside of the instance, I believe you must have ZObjectManager as one of the base classes. [I haven't tried it without ZObjectManager as a base class, but I know it works when you do.] [end quote] Kevin -----Original Message----- From: Edd Dumbill <edd@usefulinc.com> To: Michel Pelletier <michel@digicool.com> Cc: Edd Dumbill <edd@usefulinc.com>; zope@zope.org <zope@zope.org> Date: Monday, November 01, 1999 12:54 PM Subject: Re: [Zope] Altering product instance changes all instances!
On Mon, Nov 01, 1999 at 11:52:20AM -0500, Michel Pelletier wrote:
Edd Dumbill wrote:
Hi
For my SiteSummary [1] product, I have a default image that is stored
as a
subobject in my ZClass.
An instance of the product can upload a new image to replace it.
Unfortunately that ends up replacing the image in _all_ instances of the product.
This is not the desired behavior!
But it is probably the correcy behavior.
Yes, I figured so
It sounds like maybe you want your object to be an ObjectManager, and contain your Image.
My object subclasses ObjectManager already. The only way I figure to get round this is to add to the constructor some code which clones the Image in the class and adds it to the object itself. I am dubious as to whether I can achieve this in DTML -- it's looking like I need an external method to achieve it.
I suppose the 'right' thing would be for each instance to set an instance attribute when they are instanciated, but you can't do that, because you can't set attributes from DTML, it would violate security. You *can* do it from an external method, but that might be hairy..hmm.
The 'right' thing happens to properties. What I guess I wanted was to be able to add objects in as properties. But of course this is only possible for a ZClass that subclasses ObjectManager, so there won't be anything in the existing Zope interfaces to enable me to do that.
You might be stretching ZClasses farther than they are capable of going, at this point.
:-) I think I might.
It might be desireable for us to come up with some way for instances to change their attributes, but this is typically not done from DTML, DTML is expressly designed not to allow you to 'change' objects without using a specific API that that object provides, in Python, for the DTML programmer.
I can conceive of a need for ZClasses which subclass ObjectManager to come "pre-loaded" with objects, kind of like a default population. As I said above, I guess I can achieve this by putting them in the class and then cloning them as part of the constructor.
-Michel
Thanks for your very helpful response. I'll now look into getting my constructor to do some cloning.
-- Edd
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(Related lists - please, no cross posts or HTML encoding!
To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce
For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
participants (1)
-
Kevin Dangoor