[Zope] change properties in external methods (was get properties ....)

Elena Schulz elena.schulz@gmx.net
Fri, 22 Nov 2002 17:10:03 +0100


Hi Ausum,

ok I'll get more into detail even if some problems are already solved.
I want to upload object's with properties of different meta_types from a
local Zope to a remote Zope just via HTTP (no zexp etc. cause I have no
access and cannot add any Products to the remote Zope) :-(

I will do it with an external method based on uploadfile.py @ zope-cookbook
by pieterb

1. problem: I managed to upload files, folder, ... with title just python
scripts don't work (I'll show the code later...)
2. problem: I cannot add other properties upto now

Can anybody give some hints?

-- many thanks for your replies, Elena

the relevant codesnippets:

import urllib

.....

    # use authentication and set the user agent
    urllib._urlopener = MyUrlOpener()

.....

    if objectType != 'Folder': objectSource = object.read()     ### I get
the script-body with bindings and params

    if objectType == 'Script (Python)':
        params = urllib.urlencode({'id': objectId, 'file':objectSource})
##### this doesn't work
    else:
        params = urllib.urlencode({'id': objectId, 'title':objectTitle,
'file':objectSource})    ##### this works nicely

    myAction = actionDict[objectType]
    callURL = '/'.join([myHost, objPath, myAction])
    ## if objectType == 'Script (Python)' myAction is
'manage_addPythonScript'

    # send the file to zope
    f=urllib.urlopen(callURL, params)    ##### this works nicely exept for
'Script (Python)' type

    # add properties
    callURL = '/'.join([myHost, objPath, 'manage_addProperty'])
    for prop in object.propertyIds():
       if prop != 'title' or objectType != 'Script (Python)': ### title
exists already, scripts don't have properties
          propValue = object.getProperty(prop)
          propType = object.getPropertyType(prop)   ### up to here it works

         #### but the upload of the properties does not work
          params = urllib.urlencode({'id': prop, 'value':propValue,
'type':propType})

          #urllib._urlopener = MyUrlOpener() ### I tried to set the opener
again, but no change
          f=urllib.urlopen(callURL, params)