[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/Folder - LoadedFolder.py:1.1.2.1
Christian Theune
ct@gocept.com
Sat, 18 May 2002 06:20:49 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/Folder
In directory cvs.zope.org:/tmp/cvs-serv29187
Added Files:
Tag: ctheune-foldermove-branch
LoadedFolder.py
Log Message:
Renamed LoadedFolder.py to ../Content/Folder//LoadedFolder.py
=== Added File Zope3/lib/python/Zope/App/OFS/Content/Folder/LoadedFolder.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
Revision information:
$Id: LoadedFolder.py,v 1.1.2.1 2002/05/18 10:20:48 ctheune Exp $
Implemented LoadedFolder Functionality:
- Order Folder items
- Define a max amount of items possible
Todo Functionality:
- Define what content objects can be added (user)
(* notice isAddable; adding an interfaces service could make
this functionality more usable TTW)
+ add the option to the configuration zpt
+ how does the security work for this? like if this folder is
created under a folder that doesnt allow images for example?
so need to figure out how to get a list of "allowed" content
objects. also, will what can be added to this folder be
static or dynamic in the sence of if security settings change
will this folder know about it?
"""
from Folder import Folder, IFolder
from FolderLimit import FolderLimit, FolderLimitExceededError
from OrderedFolder import OrderedFolder
from types import StringTypes
from Zope.App.OFS.Container.Exceptions import UnaddableError
def membership_check(group, item): # use later for more interesting isAddable implementations
if type(group) is tuple:
for inter in group:
if membership_check(inter, item):
return 1
return 0
if type(item) is tuple:
for inter in item:
if membership_check(group, inter):
return 1
return 0
return group is item or issubclass(item, group)
class ILoadedFolder(IFolder):
"""The standard Zope Loaded Folder object interface."""
class LoadedFolder(Folder, FolderLimit, OrderedFolder):
"""Implements some nice additional features to the regular
Folder.
"""
__implements__ = (ILoadedFolder,) + \
Folder.__implements__ + \
FolderLimit.__implements__ + \
OrderedFolder.__implements__
# XXX Reimplementation of some of the IReadContainer API. Shrug.
def objectIds(self):
"""Return a sequence-like object containing the names
associated with the objects that appear in the folder
"""
return self._orderedIds
def objectValues(self):
"""Return a sequence-like object containing the objects that
appear in the folder.
"""
result = []
for id in self.objectIds():
result.append(self.data[id])
return tuple(result)
def objectItems(self):
"""Return a sequence-like object containing tuples of the form
(name, object) for the objects that appear in the folder.
"""
result = []
for id in self.objectIds():
result.append((id, self.data[id]))
return result
# XXX Reimplementation of some of the IWriteContainer API. Shrug again.
def setObject(self, name, object):
"""Add the given object to the folder under the given name."""
if type(name) in StringTypes and len(name)==0:
raise ValueError
if not self.isAddable(getattr(object,'__implements__', None)):
raise UnaddableError (self, object, name)
if self.isLimitReached():
raise FolderLimitExceededError(self, object,
'The folder\'s limit (%d item%s) was exeeded.' %
(self.getLimit(), self.getLimit()==1 and "" or "s" ))
else:
self.data[name] = object
if name not in self._orderedIds:
self._orderedIds += (name,)
def delObject(self, name):
"""Delete the named object from the folder. Raises a KeyError
if the object is not found."""
del self.data[name]
ids = list(self._orderedIds)
ids.remove(name)
self._orderedIds = tuple(ids)
def isAddable(self, interfaces):
return 1 # could return 0 if self.isLimitReached(), and eliminate check above...