[Zope3-Users] Question about "ForbiddenAttribute"...
Thierry FLORAC
tflorac at ulthar.net
Mon Jun 12 19:33:06 EDT 2006
Hi,
I'm trying to build a sample photos management application for Zope-3.2,
with the following interfaces and classes :
- class IGalleryPhoto(IContainer)
...
- class IGalleryContainer(IContainer)
(marker interface used for preconditions)
- class IGalleryFolder(IGalleryContainer)
def getImages():
...
- class IGallery(IGalleryFolder,IPossibleSite)
...
- class GalleryPhoto(BTreeContainer)
...
- class GalleryFolder(Folder)
def getImages(self):
return [item for item in self.values()
if IGalleryPhoto.providedBy(item)]
- class Gallery(GalleryFolder, SiteManagerContainer)
...
Until now, it's OK !
After that, I created a sample view based on a page template for
IGalleryFolder, using a view class :
- <tal:x repeat="image view/getImages"> ... </tal:x>
- class FolderInfo:
def getImages(self):
"""Get a sorted list of images"""
result = IGalleryFolder(self.context).getImages()
result.sort (lambda x,y: cmp(IGalleryPhoto(x).name,
IGalleryPhoto(y).name))
return result
The view is registered in ZCML like this :
<page
name="images.html"
for=".interfaces.IGalleryFolder"
allowed_interface=".interfaces.IGalleryPhoto"
template="folder_images.pt"
permission="zope.View"
class=".folder.FolderInfo"
menu="zmi_views" title="Images" />
But when trying to display the view, a ForbiddenAttribute exception is
raised :
File ".../browser/folder.py", line 39, in getImages
result.sort (lambda x,y:
cmp(IGalleryPhoto(x).name,IGalleryPhoto(y).name))
ForbiddenAttribute:('sort',[<GalleryPhoto object at 0xa5b378ac>,...]
So the forbidden attribute seems to be the "sort" method of the
resulting array, which of course isn't part of any of my interfaces.
In such a case, I solved the problem by moving the "getSortedImages" to
the folder interface and content class.
But that may not always be possible, so how can I get access to such
methods ??
Thanks for any help,
Thierry
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Zope3-users
mailing list