Hi, I have a problem with the "Photo" product. I want to create a Photo object from an existing Image object. I have a form with id and title input tags which are initialized with appropriate values from a special folder where the Image objects resides . Now I have written a PythonSript to handle the creation of a new Photo object #id1,title1 image id and tile def doAddPhoto(id1, title1): # some comments .... img = context.getObjectById(id1) # this returns the object part of object item array from context.objectItems s="ph" +str(id1) context.manage_addPhoto(id=s, file=img.data,title=title1, displays=None, precondition='', content_type='image/jpeg') (line 12) If I submit the form, an error occurs: Traceback (innermost last): Module ZPublisher.Publish, line 101, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Shared.DC.Scripts.Bindings, line 306, in __call__ Module Shared.DC.Scripts.Bindings, line 343, in _bindAndExec Module Products.PythonScripts.PythonScript, line 323, in _exec Module None, line 12, in doAddPhoto - <PythonScript at /www.ecommerce.de/doAddPhoto> - Line 12 AttributeError: manage_addPhoto When I try it with context.manage_addImage everything works fine. I can't figure out why the above Exception is thrown, the source code of Photo's manage_addPhoto function looks as similar as the manage_addImage function of the Image class (from which Photo is derived) and i have no clue where the pitfall is. Does anybody have an idea or a hint? Help would be appreciate. Thanks in advance Thomas Adams
#id1,title1 image id and tile def doAddPhoto(id1, title1): # some comments ....
img = context.getObjectById(id1) # this returns the object part of object item array from context.objectItems s="ph" +str(id1) context.manage_addPhoto(id=s, file=img.data,title=title1, displays=None, precondition='', content_type='image/jpeg') (line 12)
It should be: product_context = context.manage_addProduct['Photo'] product_context.manage_addPhoto(id=s, ......) Not so obvious to know :( You can get hints like this by viewing the source of any ZMI page that has the Add object drop down. -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Peter Bengtsson schrieb:
#id1,title1 image id and tile def doAddPhoto(id1, title1): # some comments ....
img = context.getObjectById(id1) # this returns the object part of object item array from context.objectItems s="ph" +str(id1) context.manage_addPhoto(id=s, file=img.data,title=title1, displays=None, precondition='', content_type='image/jpeg') (line 12)
It should be: product_context = context.manage_addProduct['Photo'] product_context.manage_addPhoto(id=s, ......)
Not so obvious to know :( You can get hints like this by viewing the source of any ZMI page that has the Add object drop down.
Thanks, that works, but in addition there is an photo.manage_upload(file=img.data) necessary too see the images. Regards Thomas Adams
participants (2)
-
Peter Bengtsson -
Thomas Adams