Re: [Zope] changing the meta_type for python product class

2006-12-07 Thread Dieter Maurer
Dragos Chirila wrote at 2006-12-6 20:53 +0200:
Ok, you are right, but if I do it why the ZMI is showing to me the new
meta type for both instances? This is wrong...

You have to distinquish between attributes defined on class and those
defined on instance level.

Attributes defined on class level are not persisted. When you change
the attribute on the class, all class instances will see the change.

Attributes defined on instance level are persisted. If you later
change the value used to initialize the attribute, only newly created
instances will get this new value; old instances will retain the old
value.


meta_type is usually defined on class level.
This is also the case in your situation -- as you see the value
changing, when you change the class definition.


Also, I don't understand why if I explicit change the meta_type
property for the old instance (e.g. a method of MyClass that is called
via URL) still nothing happens?

If you change meta_type on a specific instance, then it will stick
and no longer follow any modifications in the class.

I also tried to add the following lines to the MyClass:

_properties = (
Folder._properties
+
(
{'id': 'meta_type', 'type': 'string', 'mode': 'w'},
)
)

In the Properties tab for both instances the same value is shown for
the meta_type property.

Only after you changed the properties at least once, become the
properties instance level attributes (there might even be
an optimization that a property is not written when its value did not
change. In this case, you would need to change the properties value
in order to make it an instance attribute). Up to that point,
the default value defined on class level is used.



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] changing the meta_type for python product class

2006-12-06 Thread Dragos Chirila

Hi everybody,

I am stuck with the following problem for witch I don't have a
solution. I would appreciate it very much if you could help me with
it.

I have a very simple Python product with only one class that extends
Folder. The name of the product is MyClass and the MyClass.py module
is below:

from OFS.Folder import Folder
from Products.PageTemplates.PageTemplateFile import PageTemplateFile

from constants import *

manage_addMyClass_html = PageTemplateFile('zpt/myclass_manage_add', globals())
def manage_addMyClass(self, id, title='', REQUEST=None):

   ob = MyClass(id, title)
   self._setObject(id, ob)
   if REQUEST:
   return self.manage_main(self, REQUEST, update_menu=1)

class MyClass(Folder):


   meta_type = METATYPE_MYCLASS

   def __init__(self, id, title):
   #constructor
   self.id = id
   self.title = title

And the constants.py module contains:

import Globals

MYCLASS_PRODUCT_NAME = 'MyClass'
MYCLASS_PRODUCT_PATH = Globals.package_home(globals())

METATYPE_MYCLASS = 'My Class'
PERMISSION_ADD_MYCLASS = 'MyClass - Add Components'

In the ROOT folder I create the following python script (listing):

for x in container.objectValues(['My Class']):
 print '[%s] - [%s]' % (x.meta_type, x.absolute_url())
return printed


Then I follow the steps:

1. Create an instance with the id 'instance1' (in the drop down I have
'My Class').
2. I run the 'listing' script and I get:

[My Class] - [http://10.0.0.37:8080/instance1]

3. I change the constant METATYPE_MYCLASS into 'My New Class'
4. I run the 'listing' script and I get:

[My New Class] - [http://10.0.0.37:8080/instance1]

5. I create a second instance with the id 'instance2' (in the drop
down I have 'My New Class').
6. I run the 'listing' script and I get:

[My New Class] - [http://10.0.0.37:8080/instance1]

7. I modify the python script by changing the 'My Class' with 'My New Class'
8. I run the 'listing' script and I get:

[My New Class] - [http://10.0.0.37:8080/instance2]

In the ZMI for both instances the meta_type 'My New Class' is
displayed. I don't understand why the first instance is not displayed
after I change the meta_type value in the python Product.
Moreover, if I try to explicit update the meta_type property for the
first instance to the new value, the result is the same.

What I am trying to accomplish is to be able to change the meta_type
value and this to work (e.g. with no effect on python scripts like
'listing')

Thank you very much,
Dragos
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] changing the meta_type for python product class

2006-12-06 Thread Dragos Chirila

Hi!

Thank you very much for your response.

Ok, you are right, but if I do it why the ZMI is showing to me the new
meta type for both instances? This is wrong...

Also, I don't understand why if I explicit change the meta_type
property for the old instance (e.g. a method of MyClass that is called
via URL) still nothing happens?

I also tried to add the following lines to the MyClass:

   _properties = (
   Folder._properties
   +
   (
   {'id': 'meta_type', 'type': 'string', 'mode': 'w'},
   )
   )

In the Properties tab for both instances the same value is shown for
the meta_type property.

Thank you very much once again for taking time to consider my problem.

Regards,
Dragos.

On 12/6/06, Dieter Maurer [EMAIL PROTECTED] wrote:

Dragos Chirila wrote at 2006-12-6 15:48 +0200:
 ...
What I am trying to accomplish is to be able to change the meta_type
value and this to work (e.g. with no effect on python scripts like
'listing')

The best way is *NOT* to change the meta type (at least not when
you have places that require it unchanged).

Instead derive a new class from it and give this new class a new
meta_type.



--
Dieter


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )