[Zope] Re: Change a ZClass's instance's image

Albert Kinderman albert.kinderman@csun.edu
Tue, 05 Oct 1999 20:59:32 +0000


Kevin Dangoor gave me the solution to a similar problem.  However, it
takes two steps as currently implemented.  

1)  A copy of the default (image, document ,etc) is created in the
instance.

2)  You go to the instance and change the default to the new (image,
document, etc) 

If you can find a way to do it all in one step, please let me know.  

As you have discovered, if you don't make a copy, the object in the
instance is (a pointer back to) the original.  If you do not create a
copy, any changes you make are to the original. 

Quoting my response to his email (posted to the list on October 1)

[BEGIN QUOTE]

Here is a quick write-up for others taken from the example of KM|Net
News.

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 OF QUOTE]

change the words document to image appropriately, and you might have
your solution.

Al



> --__--__--
> 
> Message: 55
> Date: Tue, 05 Oct 1999 13:17:08 +0000
> Subject: [Zope] Change a ZClass's instance's image
> From: "Kam Cheung" <zope@littlecircle.com>
> To: Zope <zope@zope.org>
> 
> I created a ZClass, let's call it "TestZClass". It's a very simple ZClass --
> it has an image and an index_html method.
> 
> TestZClass
>     TestImage
>     index_html
> 
> In the TestZClass_add constructor, I put in a code fragment like this:
> 
> <dtml-with "TestZClass.createInObjectManager(REQUEST['id'], REQUEST)">
>     <dtml-call "TestImage.manage_upload(REQUEST['uploadImage'])">
> </dtml-with>
> 
> In the TestZClass_addForm HTML, I have:
> 
> <form action="TestZClass_add" METHOD="post" ENCTYPE="multipart/form-data">
> <table>
>     <tr>
>         <th>Id:</th>
>         <td><INPUT TYPE="text" NAME="id" SIZE="40"></td>
>     </tr>
>     <tr>
>         <th>Image:</th>
>         <td><INPUT TYPE="file" NAME="uploadImage" SIZE="25"></td>
>     </tr>
>     <tr>
>         <td></td>
>         <td><INPUT TYPE="submit" VALUE=" Add "></td>
>     </tr>
> </table>
> </form>
> 
> What I want to do is, when the addForm HTML is called, one can upload an
> image and create an instance of TestZClass that overides the default
> TestImage in the original Class.
> 
> It does override the original TestImage, but if one make another instance of
> TestZClass, the TestImage of all the other instances will be changed to the
> latest uploaded image.
> 
> For example, if I create an instance of TestZClass, call it Instance1 and
> upload an image Image1. Instance1' TestImage will become Image1. However, if
> I create another instance of TestZClass, let's call it Instance2 and upload
> Image2, then not only Instance2's TestImage will become Image2, but
> Instance1's TestImage will also be changed to Image2!!!
> 
> When I go back to check the TestZClass, it's very clear to me that, the
> TestZClass constructor change the TestImage on the ZClass, not on the
> instance.
> 
> Anyone know how I can force it to change the TestImage in the instance, not
> the ZClass?
> 
> Kam
> 

-- 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Albert Kinderman              California State University, Northridge
albert.kinderman@csun.edu     Department of Management Science