Re: [Zope3-Users] Getting the content object from a widget
On Monday 14 November 2005 06:44, Johan Carlsson wrote: > 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). Well, there are basically two use cases: (1) The field is bound and in this case the context of the field is the content. (2) The field is not bound and thus there is no content object. I think those two cases are not too hard to handle, or am I wrong? Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Fwd: Re: [Zope3-Users] Getting the content object from a widget]
Original Message Subject: Re: [Zope3-Users] Getting the content object from a widget Date: Mon, 14 Nov 2005 14:14:02 +0100 From: Johan Carlsson <[EMAIL PROTECTED]> To: Johan Carlsson <[EMAIL PROTECTED]> References: <[EMAIL PROTECTED]> Johan Carlsson wrote: Well, I extended the search loop to look like this: def _getParent(self): curr=self while hasattr(curr, 'context') and \ (IField.providedBy(curr) or \ IInputWidget.providedBy(curr)): curr=curr.context return curr Which means that it returnes the first non field non widget it finds. It kind of does the trick. One would have though I could just use: def _getParent(self): field=self.context content=field.context return content But there is situations where a widget has a widget as it's context. For instance the default ObjectWidget uses an ObjectWidgetView as it's view class and when ObjectWidget sets it up it supplies context=self (e.g. a widget as context). I don't know why it's designed this way, in my ImageWidget, which is based on ObjectWidget, I've cut out the ObjectWidgetView and does every thing in the first view class. I did need to change the page template to use view instead of context but othervice it works ok (so far). If anyones interested I can make the ImageField code available. Regards, Johan -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72Email: [EMAIL PROTECTED] SE-113 37 STOCKHOLM -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72Email: [EMAIL PROTECTED] SE-113 37 STOCKHOLM ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Getting the content object from a widget
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 72Email: [EMAIL PROTECTED] SE-113 37 STOCKHOLM ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users