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

Johan Carlsson johanc at easypublisher.com
Mon Nov 14 08:43:33 EST 2005



-------- 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 <johanc at easypublisher.com>
To: Johan Carlsson <johanc at easypublisher.com>
References: <437878AC.9090703 at easypublisher.com>

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 72            Email: johanc at easypublisher.com
SE-113 37 STOCKHOLM

-- 
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