[Zope] Re: Uploading photos into newly created objects

Tres Seaver tseaver at palladion.com
Tue Oct 24 07:13:15 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter Bengtsson wrote:
> I'm trying to upload a Photo into a newly create object in my product
> class. The code looks something like this::
> 
> def manage_addSomething(dispatcher, id, title, photofile):
>     destination = dispatcher.Destination()
>     instance = Something(id, title)
>     destination._setObject(id, instance)
>     obj = destination._getOb(id)
>     # at this point, is 'obj' wrapped in aq stuff???
> 
>     _adder = obj.manage_addProduct['Photo'].manage_addPhoto
>     _adder(id='', title='', file=photofile)
> 
> class Something(Folder):
>     def __init__(self, id, title):
>         self.id = id
>         self.title = title
> 
> 
> The error I get is:
>   File "/home/peterbe/zope/zope285/Products/Photo/Photo.py", line 664,
> in manage_addPhoto
>     dest._setObject(id, photo)
> AttributeError: _setObject
> 
> I'm using Photo product 1.2.3 but I don't think it matters if it's a
> Photo I'm trying to add or any other product.
> 
> If I add the photo after the transaction has been completed in a
> separate request it works fine to add the photo to the recently created
> object.
> 
> Any idea?

I don't actually use the 'Destination' bit, ever (in fact, I don't
remember ever even seeing it used).  By inspection (in
'App.FacdtoryDispatcher'), it looks as though the metho returns an
unwrapped object, which would be a Bad Thing.

Can you modify the factory to just call '._setObject' on the dispatcher?
Also, I would probably just import the Photo class directly, rather than
setting up another dispatcher layer.  E.g., ::

 def manage_addSomething(dispatcher, id, title, photofile):
     from Products.whatever.photo import Photo
     instance = Something(id, title)
     dispatcher._setObject(id, instance)
     obj = dispatcher._getOb(id)

     photo = Photo(id='photo', title='', file=photofile)
     ob._setObject('photo', photo)



Tres.
- --
===================================================================
Tres Seaver          +1 202-558-7113          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFPfVK+gerLs4ltQ4RApPbAJ9rUVyhfFJqMdh1s6eaBTWSYHPUkACfUT3v
hK6ZaweTGFwrfKgtmuB3F3Y=
=6GIq
-----END PGP SIGNATURE-----



More information about the Zope mailing list