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

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

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


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
  Tél. : +33
  Fax. : +33
Zope3-users mailing list

Reply via email to