[Zope] change properties in external methods (was get properties ....)
Ausum Studio
ausum_studio@hotmail.com
Sat, 23 Nov 2002 08:43:25 -0500
You may want to try the ZSyncer product:
http://www.zope.org/Members/andym/ZSyncer
Anyhow, here you have some hints for your current purpose:
> myAction is 'manage_addPythonScript'
myAction should be 'manage_addProduct/PythonScripts/manage_addPythonScript'
. PythonScripts need to be created this way, when using an URL.
> #### but the upload of the properties does not work
> params = urllib.urlencode({'id': prop,
'value':propValue,'type':propType})
That should work fine, for string properties. Nonetheless, try to add the
type to the 'id' key: (untested)
params = urllib.urlencode({'id': '%s:%s' % (prop, propType),
'value':propValue,'type':propType})
Ausum
----- Original Message -----
From: "Elena Schulz" <elena.schulz@gmx.net>
To: "Ausum Studio" <ausum_studio@hotmail.com>; <zope@zope.org>
Sent: Friday, November 22, 2002 11:10 AM
Subject: Re: [Zope] change properties in external methods (was get
properties ....)
> 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)
>