[Zope-CMF] Help needed - creating objects using a specified path string or tuple

altkey myaltkey at msn.com
Fri Feb 6 00:44:31 EST 2004


Hi,

I am fairly new to zope & python but I am working to migrate some 
data/objects from zope 2.6.1 to zope 2.7.0-b2 (and eventually 2.7.0 final).

What I am doing is this.
     (1) get Dublin core metadata + some Dublin core extensions for the 
objects
     (2) get pure text representation of object content - I can't use  a 
simple import/export in zexp format because the classes in the receiving 
zope instance differ significantly from the classes in the sending zope 
instance.

I am able to collect all the data mentioned above and pass it across to 
the new 2.7.0-b2 zope instance but i am having trouble getting my 
objects to live where they need to live; specifically their path is not 
being accepted properly when i recreate the objects.

here's a code snippet for an external method i am working on

<preliminary stuff removed ...>

def addObjects(self, objectList):
   '''
   '''
   from copy import copy, deepcopy
   count = 0
   basePath = self.getPhysicalPath()
   relativePath = ()
   nameList = []
   for myObject in objectList:
     count += 1
     ob = deepcopy(myObject)
     metadata = ob[0]
     contents = ob[1]
     content = contents['CONTENTS']

     originalPath = metadata['PATH']
     #assume that the first object in the list is folderish
     if count == 1:
       unwantedPath = originalPath[:len(originalPath)-1]
       path = deepcopy(basePath)
     else:
       relativePath = originalPath[len(unwantedPath):len(originalPath)-1]
       path = basePath+tuple(relativePath)
     portalType = metadata['PORTAL_TYPE']
     metaType = metadata['META_TYPE']
     name = metadata['OBJECT_ID']

     startHere = self.restrictedTraverse(path)
     startHerePath = startHere.getPhysicalPath()
     startHere.invokeFactory(portalType,name)
     newObject = self.restrictedTraverse(path+(name,))
     newPath = newObject.getPhysicalPath()

     _addContent(self,newObject,metadata,content)
     nameList.append(('desired path='+'/'.join(path),'supplied 
context='+'/'.join(startHerePath) ,'actual path='+'/'.join(newPath)))

<clean up stuff removed ...>

here what i see as output

(	'desired path=/DF/A_Test_Folder',
	'supplied context=/DF/A_Test_Folder',
	'actual path=/DF/01_project'),
(	'desired path=/DF/A_Test_Folder/01_project', 	
	'supplied context=/DF/01_project',
	'actual path=/DF/01_project/03_df_contact_details'),
(	'desired path=/DF/A_Test_Folder/01_project',
	'supplied context=/DF/01_project',
	'actual path=/DF/01_project/02_df_partnerships'),
(	'desired path=/DF/A_Test_Folder/01_project',
	'supplied context=/DF/01_project',
	'actual path=/DF/01_project/index_html'),
etc ...


the line "self.invokeFactory(portalType,name)" should be creating the 
new objects which should be created in the context (self) that the 
external method is executing in. As can be seen, the desired path and 
the actual path differ, and since the first 'folder' is created at /DF 
instread of at /DF/A_Test_Folder all of the subsequent objects are 
created using the actual path.

I am sure this all come down to my own inexperience but I would really 
appreciate any advice that a more experiences python/zope person can give.

Cheers,
altkey (aka Phil)





More information about the Zope-CMF mailing list