<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.10.3">
</HEAD>
<BODY>
Le mercredi 11 octobre 2006 &#224; 00:52 +0200, Thierry FLORAC a &#233;crit&nbsp;:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">  Hi,</FONT>

<FONT COLOR="#000000">I try to setup a little application but have a probably little problem</FONT>
<FONT COLOR="#000000">with a ForbiddenAttribute exception on &quot;location.locate&quot; method.</FONT>
<FONT COLOR="#000000">Here is my setup :</FONT>

<FONT COLOR="#000000">        class IPhoto(IContainer,IContained):</FONT>
<FONT COLOR="#000000">            &quot;&quot;&quot;Photo handling interface&quot;&quot;&quot;</FONT>
<FONT COLOR="#000000">            ...</FONT>
<FONT COLOR="#000000">            image = Bytes(...)</FONT>
<FONT COLOR="#000000">            ...</FONT>
<FONT COLOR="#000000">        </FONT>
<FONT COLOR="#000000">        class Photo(Folder):</FONT>
<FONT COLOR="#000000">            &quot;&quot;&quot;Photo handling class&quot;&quot;&quot;</FONT>
<FONT COLOR="#000000">            ...</FONT>
<FONT COLOR="#000000">            image = None</FONT>
<FONT COLOR="#000000">            def __init__(self, image=None):</FONT>
<FONT COLOR="#000000">                super(Photo,self).__init__()</FONT>
<FONT COLOR="#000000">                self.__parent__ = self.__name__ = None</FONT>
<FONT COLOR="#000000">                if image:</FONT>
<FONT COLOR="#000000">                    self.image = image</FONT>
<FONT COLOR="#000000">            ...</FONT>
<FONT COLOR="#000000">        </FONT>
<FONT COLOR="#000000">        class IEvent(IContained):</FONT>
<FONT COLOR="#000000">            &quot;&quot;&quot;Event handling interface&quot;&quot;&quot;</FONT>
<FONT COLOR="#000000">            ...</FONT>
<FONT COLOR="#000000">        </FONT>
<FONT COLOR="#000000">        class Event(Persistent):</FONT>
<FONT COLOR="#000000">            &quot;&quot;&quot;Event handling class&quot;&quot;&quot;</FONT>
<FONT COLOR="#000000">            ...</FONT>
<FONT COLOR="#000000">            def __init__(self):</FONT>
<FONT COLOR="#000000">                super(Event,self).__init__()</FONT>
<FONT COLOR="#000000">                self.__parent__ = self.__name__ = None</FONT>

<FONT COLOR="#000000">In my event creation form (derived from formlib.AddForm), I put</FONT>
<FONT COLOR="#000000">something like this, without a problem :</FONT>

<FONT COLOR="#000000">        def create(self, data):</FONT>
<FONT COLOR="#000000">            event = Event()</FONT>
<FONT COLOR="#000000">            if data.has_key('image'):</FONT>
<FONT COLOR="#000000">                event.image = Photo(image=data['image'])</FONT>
<FONT COLOR="#000000">                location.locate(event.image, event, 'image')</FONT>
<FONT COLOR="#000000">            form.applyChanges(event, self.form_fields, data)</FONT>
<FONT COLOR="#000000">            return event</FONT>

<FONT COLOR="#000000">&quot;event.image&quot; access can then be granted easily in an URL through a</FONT>
<FONT COLOR="#000000">&quot;z3c.traverser&quot; plug-in and everything works fine... until now !</FONT>
<FONT COLOR="#000000">Because when I'm trying to make the same thing in an edit form to update</FONT>
<FONT COLOR="#000000">an existing event, an exception is raised :</FONT>

<FONT COLOR="#000000">        def edit(self, action, data):</FONT>
<FONT COLOR="#000000">            changed = False</FONT>
<FONT COLOR="#000000">            event = self.context</FONT>
<FONT COLOR="#000000">            if data.has_key('image'):</FONT>
<FONT COLOR="#000000">                event.image = Photo(image=data['image'])</FONT>
<FONT COLOR="#000000">                location.locate(event.image, event, 'image')</FONT>
<FONT COLOR="#000000">                changed = True</FONT>
<FONT COLOR="#000000">            return super(EventEditForm,self).edit(action, data) or</FONT>
<FONT COLOR="#000000">        changed</FONT>

<FONT COLOR="#000000">Here is the traceback :</FONT>

<FONT COLOR="#000000">Traceback (most recent call last):</FONT>
<FONT COLOR="#000000">  File &quot;/usr/local/zope/3.3.0/lib/python/zope/publisher/publish.py&quot;, line 133, in publish</FONT>
<FONT COLOR="#000000">        result = publication.callObject(request, obj)</FONT>
<FONT COLOR="#000000">  File &quot;/usr/local/zope/3.3.0/lib/python/zope/app/publication/zopepublication.py&quot;, line 161, in callObject</FONT>
<FONT COLOR="#000000">    return mapply(ob, request.getPositionalArguments(), request)</FONT>
<FONT COLOR="#000000">  File &quot;/usr/local/zope/3.3.0/lib/python/zope/publisher/publish.py&quot;, line 108, in mapply</FONT>
<FONT COLOR="#000000">    return debug_call(obj, args)</FONT>
<FONT COLOR="#000000">   - __traceback_info__: &lt;security proxied zope.app.publisher.browser.viewmeta.NewsEventEditForm instance at 0xa677e20c&gt;</FONT>
<FONT COLOR="#000000">  File &quot;/usr/local/zope/3.3.0/lib/python/zope/publisher/publish.py&quot;, line 114, in debug_call</FONT>
<FONT COLOR="#000000">    return obj(*args)</FONT>
<FONT COLOR="#000000">  File &quot;/usr/local/zope/3.3/lib/python/zope/formlib/form.py&quot;, line 751, in __call__</FONT>
<FONT COLOR="#000000">    self.update()</FONT>
<FONT COLOR="#000000">  File &quot;/usr/local/zope/3.3/lib/python/zope/formlib/form.py&quot;, line 732, in update</FONT>
<FONT COLOR="#000000">    result = action.success(data)</FONT>
<FONT COLOR="#000000">  File &quot;/usr/local/zope/3.3/lib/python/zope/formlib/form.py&quot;, line 582, in success</FONT>
<FONT COLOR="#000000">    return self.success_handler(self.form, self, data)</FONT>
<FONT COLOR="#000000">  File &quot;/var/local/zope/3.3/lib/python/ulthar/forms/forms.py&quot;, line 104, in handle_edit_action</FONT>
<FONT COLOR="#000000">    self.edit_action(action,data)</FONT>
<FONT COLOR="#000000">  File &quot;/var/local/zope/3.3/lib/python/ulthar/forms/forms.py&quot;, line 107, in edit_action</FONT>
<FONT COLOR="#000000">    if not self.edit(action, data):</FONT>
<FONT COLOR="#000000">  File &quot;/var/local/zope/3.3/lib/python/usf/news/browser/event.py&quot;, line 85, in edit</FONT>
<FONT COLOR="#000000">    location.locate(event.image, event, 'image')</FONT>
<FONT COLOR="#000000">  File &quot;/usr/local/zope/3.3.0/lib/python/zope/location/location.py&quot;, line 71, in locate</FONT>
<FONT COLOR="#000000">    object.__parent__ = parent</FONT>
<FONT COLOR="#000000">ForbiddenAttribute: ('__parent__', &lt;gallery.photo.Photo object at 0xa678f62c&gt;)</FONT>
</PRE>
</BLOCKQUOTE>
<BR>
Hi,<BR>
<BR>
I finally solved this stupid problem by myself...<BR>
Switching &quot;location.locate&quot; method call from &quot;EditForm&quot; view to &quot;Event&quot; class was just enough...<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<BR>
&nbsp; Thierry Florac<BR>
-- <BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
&nbsp; Chef de projet intranet/internet<BR>
&nbsp; Office National des For&#234;ts - D&#233;partement Informatique<BR>
&nbsp; 2, Avenue de Saint-Mand&#233;<BR>
&nbsp; 75570 PARIS Cedex 12<BR>
&nbsp; M&#233;l : thierry.florac@onf.fr<BR>
&nbsp; T&#233;l. : +33 01.40.19.59.64<BR>
&nbsp; Fax. : +33 01.40.19.59.85
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>