[Zope3-Users] ForbiddenAttribute on "locate" method

Thierry Florac thierry.florac at onf.fr
Wed Oct 11 03:47:41 EDT 2006


Le mercredi 11 octobre 2006 à 00:52 +0200, Thierry FLORAC a écrit :

>   Hi,
> 
> I try to setup a little application but have a probably little problem
> with a ForbiddenAttribute exception on "location.locate" method.
> Here is my setup :
> 
>         class IPhoto(IContainer,IContained):
>             """Photo handling interface"""
>             ...
>             image = Bytes(...)
>             ...
>         
>         class Photo(Folder):
>             """Photo handling class"""
>             ...
>             image = None
>             def __init__(self, image=None):
>                 super(Photo,self).__init__()
>                 self.__parent__ = self.__name__ = None
>                 if image:
>                     self.image = image
>             ...
>         
>         class IEvent(IContained):
>             """Event handling interface"""
>             ...
>         
>         class Event(Persistent):
>             """Event handling class"""
>             ...
>             def __init__(self):
>                 super(Event,self).__init__()
>                 self.__parent__ = self.__name__ = None
> 
> In my event creation form (derived from formlib.AddForm), I put
> something like this, without a problem :
> 
>         def create(self, data):
>             event = Event()
>             if data.has_key('image'):
>                 event.image = Photo(image=data['image'])
>                 location.locate(event.image, event, 'image')
>             form.applyChanges(event, self.form_fields, data)
>             return event
> 
> "event.image" access can then be granted easily in an URL through a
> "z3c.traverser" plug-in and everything works fine... until now !
> Because when I'm trying to make the same thing in an edit form to update
> an existing event, an exception is raised :
> 
>         def edit(self, action, data):
>             changed = False
>             event = self.context
>             if data.has_key('image'):
>                 event.image = Photo(image=data['image'])
>                 location.locate(event.image, event, 'image')
>                 changed = True
>             return super(EventEditForm,self).edit(action, data) or
>         changed
> 
> Here is the traceback :
> 
> Traceback (most recent call last):
>   File "/usr/local/zope/3.3.0/lib/python/zope/publisher/publish.py", line 133, in publish
>         result = publication.callObject(request, obj)
>   File "/usr/local/zope/3.3.0/lib/python/zope/app/publication/zopepublication.py", line 161, in callObject
>     return mapply(ob, request.getPositionalArguments(), request)
>   File "/usr/local/zope/3.3.0/lib/python/zope/publisher/publish.py", line 108, in mapply
>     return debug_call(obj, args)
>    - __traceback_info__: <security proxied zope.app.publisher.browser.viewmeta.NewsEventEditForm instance at 0xa677e20c>
>   File "/usr/local/zope/3.3.0/lib/python/zope/publisher/publish.py", line 114, in debug_call
>     return obj(*args)
>   File "/usr/local/zope/3.3/lib/python/zope/formlib/form.py", line 751, in __call__
>     self.update()
>   File "/usr/local/zope/3.3/lib/python/zope/formlib/form.py", line 732, in update
>     result = action.success(data)
>   File "/usr/local/zope/3.3/lib/python/zope/formlib/form.py", line 582, in success
>     return self.success_handler(self.form, self, data)
>   File "/var/local/zope/3.3/lib/python/ulthar/forms/forms.py", line 104, in handle_edit_action
>     self.edit_action(action,data)
>   File "/var/local/zope/3.3/lib/python/ulthar/forms/forms.py", line 107, in edit_action
>     if not self.edit(action, data):
>   File "/var/local/zope/3.3/lib/python/usf/news/browser/event.py", line 85, in edit
>     location.locate(event.image, event, 'image')
>   File "/usr/local/zope/3.3.0/lib/python/zope/location/location.py", line 71, in locate
>     object.__parent__ = parent
> ForbiddenAttribute: ('__parent__', <gallery.photo.Photo object at 0xa678f62c>)


Hi,

I finally solved this stupid problem by myself...
Switching "location.locate" method call from "EditForm" view to "Event"
class was just enough...

  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : thierry.florac at onf.fr
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope3-users/attachments/20061011/a82db33b/attachment.htm


More information about the Zope3-users mailing list