[Zope] updating existing instances of a class
John Schinnerer
johnschinnerer at yahoo.com
Mon Sep 13 18:33:52 EDT 2004
Hello,
I am trying to use the below code (from zopelabs) to update my existing
class instances.
When I run the python script to invoke the external method, I get an
Attribute error on REQUEST.
I have no idea why, or how to fix - and, I don't really understand the
first part of the external method that has references to REQUEST and
sets up the value of root.
Any help appreciated...
code/comments from zopelabs recipie is:
-------------
#create a file in $ZOPE/Extensions called schema.py
def addPropertyToObjectType(self, meta_type, property, prop_type=None):
""" does a find for all meta_type's and then attaches this proeprty
to them if they dont already ahve it """
root=None
if self.REQUEST.has_key('VirtualRootPhysicalPath'):
root = self.REQUEST.VirtualRootPhysicalPath
else:
root = ('',)
root = self.restrictedTraverse(root)
for result in self.ZopeFind(root, obj_metatypes=(meta_type, ),
search_sub=1):
id, o = result[0], result[1]
if not hasattr(o, property):
setattr(o, property, prop_type)
#create a External Method id:addPropertyToMetaType
#module = schema.py and function = addPropertyToObjectType
#Now create a (Script)Python called add_body_text
context.addPropertyToMetaType('DTML Document', 'my_CustomProperty')
return 'fin'
--------------
thanks,
John S.
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
More information about the Zope
mailing list