Dear list I have a product which I want to extend. I want to add a property. In my ZODB I all ready have ~1000 objects stored. And I would hate if I have to add them again. Is there a way to update the existing objects? \Oliver
Oliver Marx wrote:
Dear list
I have a product which I want to extend. I want to add a property.
In my ZODB I all ready have ~1000 objects stored. And I would hate if I have to add them again.
Is there a way to update the existing objects?
Simply add the new property to your global class defintion and to the PropertySheet-defintion: class YourObjectClass(SimpleItem, PropertyManager): """ A class to build ... """ newProperty = '' _properties = ({'id': 'title', 'type': 'string', 'mode': 'w'}, {'id': 'newProperty', 'type': 'string', 'mode':'w'},) Zope will update your existing objects at startup this way. Cheers, Maik
Maik Jablonski wrote:
Oliver Marx wrote:
Dear list
I have a product which I want to extend. I want to add a property.
In my ZODB I all ready have ~1000 objects stored. And I would hate if I have to add them again.
Is there a way to update the existing objects?
Simply add the new property to your global class defintion and to the PropertySheet-defintion:
class YourObjectClass(SimpleItem, PropertyManager): """ A class to build ... """
newProperty = ''
_properties = ({'id': 'title', 'type': 'string', 'mode': 'w'}, {'id': 'newProperty', 'type': 'string', 'mode':'w'},)
Zope will update your existing objects at startup this way.
Cheers, Maik
I would like this newProperty to have the value aq_parent.title. But newProperty = Implicit.aq_parent.title Does not work. Can it be done? \Oliver
Hi, Is it possible to be... newProperty = self.aq_parent.title ? At 01:58 PM 2/17/2003 +0100, you wrote:
Maik Jablonski wrote:
Oliver Marx wrote:
Dear list
I have a product which I want to extend. I want to add a property.
In my ZODB I all ready have ~1000 objects stored. And I would hate if I have to add them again.
Is there a way to update the existing objects?
Simply add the new property to your global class defintion and to the PropertySheet-defintion:
class YourObjectClass(SimpleItem, PropertyManager): """ A class to build ... """
newProperty = ''
_properties = ({'id': 'title', 'type': 'string', 'mode': 'w'}, {'id': 'newProperty', 'type': 'string', 'mode':'w'},)
Zope will update your existing objects at startup this way.
Cheers, Maik
I would like this newProperty to have the value aq_parent.title. But
newProperty = Implicit.aq_parent.title
Does not work. Can it be done?
\Oliver
_______________________________________________ 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 )
Oliver Marx wrote:
I would like this newProperty to have the value aq_parent.title. But
newProperty = Implicit.aq_parent.title
Does not work. Can it be done?
You should run an update-script which sets the required value for the newProperty after "upgrading" your objects... can be easily done with ZopeFindAndApply: Zope/lib/OFS/FindSupport.py: def ZopeFindAndApply(self, obj, obj_ids=None, obj_metatypes=None, obj_searchterm=None, obj_expr=None, obj_mtime=None, obj_mspec=None, obj_permission=None, obj_roles=None, search_sub=0, REQUEST=None, result=None, pre='', apply_func=None, apply_path=''): -mj
At 04:58 AM 2/17/2003, Oliver Marx wrote:
I would like this newProperty to have the value aq_parent.title. But
newProperty = Implicit.aq_parent.title
Does not work. Can it be done?
Since this is a custom product, there may be an easier way to do this: Make newProperty a class attribute instead of an instance property: ---------- # top of head, untested from Acquisition import aq_parent class foo(various_base_classes): ... def my_parent_title(self): try: return aq_parent(self).title except: raise 'AttributeError', '%s has no parent or the parent has no title' % self.id newProperty = self.my_parent_title ---------- That way, all you'll have to do to get this attribute is refresh the product... no updating necessary. Also, even if an instance gets moved, your attribute should return correctly. HTH, Dylan
You can try this piece of code ... def __setstate__(self, state): """update""" YourObjectClass.inheritedAttribute('__setstate__')(self, state) if not hasattr(self,'newProperty'): self.newProperty = self.aq_parent.title It should work.. At 02:16 PM 2/17/2003 +0100, you wrote:
Cornel Nitu wrote:
Hi, Is it possible to be... newProperty = self.aq_parent.title ?
Nope. aq.parent is for some reason not known at this stage..
\Oliver
On Mon, Feb 17, 2003 at 03:21:19PM +0200, Cornel Nitu wrote:
You can try this piece of code ...
def __setstate__(self, state): """update""" YourObjectClass.inheritedAttribute('__setstate__')(self, state) if not hasattr(self,'newProperty'): self.newProperty = self.aq_parent.title
Hi! I tried this some time ago. This "magical" update did not work for me. If I recall correctly, the function didn't get called if a object was in memory. Now all objects have a refresh method. If I upgrade my source code I call this method for all objects. thomas -- Thomas Guettler <guettli@thomas-guettler.de> http://www.thomas-guettler.de
Thomas Guettler wrote:
On Mon, Feb 17, 2003 at 03:21:19PM +0200, Cornel Nitu wrote:
You can try this piece of code ...
def __setstate__(self, state): """update""" YourObjectClass.inheritedAttribute('__setstate__')(self, state) if not hasattr(self,'newProperty'): self.newProperty = self.aq_parent.title
Hi!
I tried this some time ago. This "magical" update did not work for me. If I recall correctly, the function didn't get called if a object was in memory.
Now all objects have a refresh method. If I upgrade my source code I call this method for all objects.
I wrote this product: http://www.zope.org/Members/chrisw/UpdateSupport/ ...to help write external methods that go through a ZODb an update all objects of a given type. It works for me and has worked for numerous Squishdot updates... cheers, Chris
participants (6)
-
Chris Withers -
Cornel Nitu -
Dylan Reinhardt -
Maik Jablonski -
Oliver Marx -
Thomas Guettler