Add Property to Image with Form & Python?
Greetings- (First, thanks to all who responded to my earlier question!) Question: I'm using a form to specify an Image and desired properties to upload. Then I use a Python script to do the actual _addImage and _addProperty. The _addImage works fine. But when I try to use the same script to add properties, I can't get it to work. The only object I can successfully add to is the image's parent folder... Here's what I have so far; the problem seems to be accessing the "id" of the image I created in the earlier lines of code: (Form) <form action ="image_action" ...> <Image: <input type="file" name="file"> <Property: <input type="text" name="author"> <input type="submit" value ="Add Image" ________________________________________________ (image_action method) <dtml-call expr="add_Image(file, author)"> ________________________________________________ #add_Image Python script # from Products.PythonScripts.standard import url_quote image_folder=container.form_images #create the new image image_folder.manage_addProduct['OFSP'].manage_addImage(id='', title='', file=file) #add an author property to image created above doc=getattr(image_folder, id) doc.manage_addProperty('author', author, 'string') _________________________________________________ Much thanks in advance!! I'm learning a lot from you all. Kevin
Kevin Jones wrote:
#add an author property to image created above doc=getattr(image_folder, id) doc.manage_addProperty('author', author, 'string')
...and you're saying that property ends up on the Image's container? Very odd :-S That SHOULD work as you expect... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Chris, All- The problem was that I didn't explicitly define "id." In the line where I add the image, I simply added:
id=image_folder.manage_addImage blah blah blah...
It is interesting that when I send over the image to be added with the form entry, the id (as we think of on a Zope object) doesn't come over with it. Hmmmm, perhaps the form <input ... type="file"> doesn't actually make it a Zope object, and neither does the Python Product to get the file from my local file system?? Which is why, as you queried, the property has no where to go but up the Zope structure until it finds something that IS an object. Not sure the above is the best way, but I got it to work. If anyone has a better way (or understanding of this), would love to know. kj Chris Withers wrote:
Kevin Jones wrote:
#add an author property to image created above doc=getattr(image_folder, id) doc.manage_addProperty('author', author, 'string')
...and you're saying that property ends up on the Image's container?
Very odd :-S
That SHOULD work as you expect...
Chris
Kevin Jones wrote:
The problem was that I didn't explicitly define "id." In the line where I add the image, I simply added:
id=image_folder.manage_addImage blah blah blah...
and that made it work? I didn't know manage_addImage returned the id of the image being added...
It is interesting that when I send over the image to be added with the form entry, the id (as we think of on a Zope object) doesn't come over with it.
Probably some namespace clash with python internal id funtion, maybe?
Hmmmm, perhaps the form <input ... type="file"> doesn't actually make it a Zope object,
Well, that will appear in the request as a FileUpload instance...
and neither does the Python Product to get the file from my local file system??
Sorry, that didn't parse as english :/
Which is why, as you queried, the property has no where to go but up the Zope structure until it finds something that IS an object.
I think your logic is going astray here. What's the FULL code of your python script that wasn't working? What's the FULL code of your python script that IS working? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Kevin Jones wrote at 2004-3-25 09:12 -0700:
... Question: I'm using a form to specify an Image and desired properties to upload. Then I use a Python script to do the actual _addImage and _addProperty. The _addImage works fine. But when I try to use the same script to add properties, I can't get it to work. The only object I can successfully add to is the image's parent folder...
What happens? Do you get an exception, when you try to add a property to something else? Are the properties just added to the wrong object? In the first case, we need to know "Error type", "Error value" and traceback. In the second case, you use "manage_addProperty" either for the wrong object or for an object that is not a "PropertyManager" ("Image" is one!). Zope's acquisition will then find the nearest "PropertyManager" "above" this object and uses its "manage_addProperty". This adds the property to this "PropertyManager". -- Dieter
participants (3)
-
Chris Withers -
Dieter Maurer -
Kevin Jones