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

2006-01-03 Thread Stephan Richter
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]

2005-11-14 Thread Johan Carlsson



 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