[Zope3-Users] Getting the content object from a widget

Johan Carlsson johanc at easypublisher.com
Mon Nov 14 06:44:44 EST 2005


Hi,
I'm having trouble in finding a consistent way to locate
the content object from a widget (view) class.
(This is when using complex widgets like the ObjectWidget.)

Some background. I'm trying to implement a ImageField and a FileField
so I can add fields for Image and File objects to my schema.
After experimenting with the IObject field for a while I've
done the following things (I've only done the Image part, but
files should be a matter of cut&paste):

- Created an ImageField class (I basically just copied the Object
   implementation)

- I've created an ImageWidget class (derived from ObjectWidget)
   and registered it as a view for the ImageField.

- I've also added a custom IImage interface and Image implementation,
   because I want to add fields to the IImage. (I'm guessing that I
   "should" use annotations, but it's not gone happen in a long while,
   this is consuming far too much of my time as it is.)

This works quite well (after endless fight with Z3 too understand how
the schema  system works).

One of the hardest problem has been how to get information about my
Image object from the view.
In the ObjectWidget view the context is the field, the field in it's
turn as a context that is the content object.
So what I've done so far is just to climb up the context tree to
get to an object not defining a context (and that has been the content
object I'm after, but this strategy doesn't work when adding a content
object for instance, because there isn't a content object too be found.)


So I'm looking for a good generic way to find the content object (or
None if it doesn't exist).

Regards,
Johan


PS. I've also noticed that to be able to make web requests to the image
object I need to specify the __name__ attribute when setting up
the the field (just so that you know). Fields normaly lack the Location
interfaces so one needs to figure out the location manually.
Also fields need special traversers to be traversable from the web,
it's a consequence of the explicit nature of Z3 I guess.)



-- 
Johan Carlsson          Tel: + 46 8 31 24 94
Colliberty              Mob: + 46 70 558 25 24
Torsgatan 72            Email: johanc at easypublisher.com
SE-113 37 STOCKHOLM


More information about the Zope3-users mailing list