[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Folder - LoadedFolder.py:1.1.4.1 LoadedFolderFields.py:1.1.4.1 OrderedFolder.py:1.1.4.1 folder.zcml:1.1.2.8 FolderAdder.py:NONE FolderContents.py:NONE add.pt:NONE add_confirmed.pt:NONE main.pt:NONE

Stephan Richter srichter@cbu.edu
Wed, 27 Mar 2002 10:55:14 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Folder
In directory cvs.zope.org:/tmp/cvs-serv12282/Folder

Modified Files:
      Tag: Zope-3x-branch
	folder.zcml 
Added Files:
      Tag: Zope-3x-branch
	LoadedFolder.py LoadedFolderFields.py OrderedFolder.py 
Removed Files:
      Tag: Zope-3x-branch
	FolderAdder.py FolderContents.py add.pt add_confirmed.pt 
	main.pt 
Log Message:
New Content Objects:

- NaiveFile --> all the data is stored in one string
- File --> Uses a BTree to store the data in chunks (more efficient)
- Image --> Can store and display an image a la Z2 (based on File)
- ZPTPage --> A simple version of ZPT for the content space to allow some 
  dynamics data (please do not use this for scripting)

Also:

- Expansion of supported views
- all edit screens are Formulator supported



=== Added File Zope3/lib/python/Zope/App/OFS/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.4.1 2002/03/27 15:54:43 srichter Exp $

Implemented LoadedFolder Functionality:

- Order Folder items
- Define a max amount of items possible

Todo Functionality:

- Define what content objects can be added (user)
  + 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, FolderLimitExeededError
from OrderedFolder import OrderedFolder


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 self.isLimitReached():
            raise FolderLimitExeededError, 'The folder\'s limit was exeeded.' 
        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)


=== Added File Zope3/lib/python/Zope/App/OFS/Folder/LoadedFolderFields.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
# 
##############################################################################
"""

$Id: LoadedFolderFields.py,v 1.1.4.1 2002/03/27 15:54:43 srichter Exp $
"""


from Zope.App.Formulator import getField


LimitField = getField('IntegerField')(
    id='limit',
    title='Limit',
    description='Limit of objects in the container.',
    start=1,
    default=1000 )


=== Added File Zope3/lib/python/Zope/App/OFS/Folder/OrderedFolder.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: OrderedFolder.py,v 1.1.4.1 2002/03/27 15:54:43 srichter Exp $

"""

from Zope.App.OFS.Container.IOrderedContainer import IOrderedContainer
from types import StringType


class OrderedFolder:
    """Adds the Ordering Feature to a Folder
    """

    __implements__ =  (IOrderedContainer,)

    _orderedIds = ()


    def moveObjectsByPositions(self, ids, positionDelta):
        """ """

        if type(ids) is StringType:
            ids = (ids,)

        # Interestingly enough, we need to switch the order when
        # moving, so that the movements won't cancel each
        # other
        if positionDelta > 0:
            ids = list(ids)
            ids.reverse()
            
        moved_objects = 0
        
        for id in ids:
            old_position = self.getObjectPosition(id)
            new_position = old_position + positionDelta
            # Make sure the new position makes sense and is valid
            if not (old_position == new_position  or
                    new_position > self.objectCount() or
                    new_position < 0):
                
                id_list = list(self._orderedIds)
                # now delete the entry ...
                id_list.remove(id)
                # ... and now add it again
                id_list.insert(new_position, id)
                self._orderedIds = tuple(id_list)

                moved_objects += 1

        return moved_objects


    ############################################################
    # Implementation methods for interface
    # Zope.App.OFS.IOrderedContainer

    def getObjectPosition(self, id):
        '''See interface IOrderedContainer'''

        if id in self._orderedIds:
            return list(self._orderedIds).index(id)
        else:
            # If the object was not found, throw an error.
            # Yeah, that is good raise 'ObjectNotFound',
            raise ( 'ObjectNotFound',
                    'The object named %s was not found.' %id)


    def moveObjectsDown(self, ids):
        '''See interface IOrderedContainer'''
        return self.moveObjectsByPositions(ids, +1)


    def moveObjectsUp(self, ids):
        '''See interface IOrderedContainer'''
        return self.moveObjectsByPositions(ids, -1)


    def moveObjectsToTop(self, ids):
        '''See interface IOrderedContainer'''
        if type(ids) is StringType:
            ids = (ids,)

        position_delta = - self.getObjectPosition(ids[0])
        return self.moveObjectsByPositions(ids, position_delta)


    def moveObjectsToBottom(self, ids):
        '''See interface IOrderedContainer'''
        if type(ids) is StringType:
            ids = (ids,)

        # Whee, we will do the reverse twice, but for going to the bottom
        # there is no other choice.
        ids = list(ids)
        ids.reverse()

        position_delta = self.objectCount() - \
                         self.getObjectPosition(ids[-1]) - 1

        return self.moveObjectsByPositions(ids, position_delta)


    def moveObjectToPosition(self, id, position):
        '''See interface IOrderedContainer'''
        return self.moveObjectsByPositions(id,
                   position - self.getObjectPosition(id))

    #
    ############################################################



=== Zope3/lib/python/Zope/App/OFS/Folder/folder.zcml 1.1.2.7 => 1.1.2.8 ===
    xmlns:security='http://namespaces.zope.org/security'
    xmlns:zmi='http://namespaces.zope.org/zmi'
-   xmlns:browser='http://namespaces.zope.org/browser'
 >
 
-<zmi:provideClass name=".Folder."
-                  permission_id="Zope.ManageContent"
-                  title="Son of Folder"
-                  description="Minimal folder" />
-
-<security:protectClass name=".Folder."
-   permission_id="Zope.View">
-  <security:instances permission_id="Zope.View" />
-  <security:protect
-      interface="Zope.ComponentArchitecture.IServiceManagerContainer." 
-      permission_id="Zope.ManageServices" />
-</security:protectClass>
-
-<security:protectClass name=".FolderContents."
-   permission_id="Zope.ManageContent" 
-   methods="index, listContentInfo, remove, removeObjects,
-            confirmRemoved, addServiceManager"/>
-
-<security:protectClass name=".FolderAdder."
-   permission_id="Zope.ManageContent" 
-   methods="index, confirmed, action, listAddableInfo" />
- 
-<browser:defaultView name="contents"
- for=".Folder.IFolder."
- factory=".FolderContents." />
-
-<browser:defaultView name="contents"
- for=".Folder.IFolder."
- factory="Zope.App.OFS.Folder.FolderContents." />
-
-
-<browser:view name="adder"
- for=".Folder.IFolder."
- factory="Zope.App.OFS.Folder.FolderAdder." />
-
-
-<!-- tabs for folder -->
-
-<zmi:tabs for=".Folder.IFolder.">
-  <zmi:tab label="Contents" action="contents;view"/>
-  <zmi:tab label="Role Permissions" action="RolePermissionsManagement;view"/>
-</zmi:tabs>
+  <!-- Simple Folder Directives -->
+
+  <zmi:provideClass name=".Folder."
+                    permission_id="Zope.ManageContent"
+                    title="Son of Folder"
+                    description="Minimal folder" />
+
+  <security:protectClass name=".Folder."
+                         permission_id="Zope.View">
+    <security:instances permission_id="Zope.View" />
+    <security:protect 
+              interface="Zope.ComponentArchitecture.IServiceManagerContainer." 
+  	      permission_id="Zope.ManageServices" />
+  </security:protectClass>
+
+  <zmi:tabs for=".Folder.IFolder.">
+    <zmi:tab label="Contents" action="contents;view"/>
+    <zmi:tab label="Role Permissions" 
+             action="RolePermissionsManagement;view"/>
+  </zmi:tabs>
+
+
+  <!-- Loaded Folder Directives -->
+
+  <zmi:provideClass name=".LoadedFolder."
+                    permission_id="Zope.ManageContent"
+                    title="Loaded Folder"
+                    description="A Folder having all the goodies." />
+
+  <security:protectClass name=".LoadedFolder."
+                         permission_id="Zope.View">
+    <security:instances permission_id="Zope.View" />
+  </security:protectClass>
+
+  <zmi:tabs for="Zope.App.OFS.Container.IContainerLimit.">
+    <zmi:tab label="Limit" action="limit;view"/>
+  </zmi:tabs>
+
+  <zmi:tabs for=".LoadedFolder.ILoadedFolder.">
+    <zmi:tab label="Contents" action="contents;view"/>
+    <zmi:tab label="Role Permissions" 
+             action="RolePermissionsManagement;view"/>
+  </zmi:tabs>
+
+
+  <!-- Further Directives -->
+
+  <include package=".Views" file="views.zcml" />
 
 </zopeConfigure>

=== Removed File Zope3/lib/python/Zope/App/OFS/Folder/FolderAdder.py ===

=== Removed File Zope3/lib/python/Zope/App/OFS/Folder/FolderContents.py ===

=== Removed File Zope3/lib/python/Zope/App/OFS/Folder/add.pt ===

=== Removed File Zope3/lib/python/Zope/App/OFS/Folder/add_confirmed.pt ===

=== Removed File Zope3/lib/python/Zope/App/OFS/Folder/main.pt ===