[Zope3-checkins] CVS: Zope3/src/zope/app/container - size.py:1.1 configure.zcml:1.3

Steve Alexander steve@cat-box.net
Fri, 27 Dec 2002 13:23:29 -0500


Update of /cvs-repository/Zope3/src/zope/app/container
In directory cvs.zope.org:/tmp/cvs-serv5454/src/zope/app/container

Modified Files:
	configure.zcml 
Added Files:
	size.py 
Log Message:
units should be singular.
added a sized adapter for containers that presents the number of items
contained.
If you have a kind of container for which it is expensive to get the
number of items contained, then you should make an ISized for that
container.


=== Added File Zope3/src/zope/app/container/size.py ===

##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
"""Adapters that give the size of an object.

$Id: size.py,v 1.1 2002/12/27 18:22:58 stevea Exp $
"""

from zope.app.interfaces.size import ISized

__metaclass__ = type

class ContainerSized:

    __implements__ = ISized
    
    def __init__(self, container):
        self._container = container

    def sizeForSorting(self):
        """See ISized"""
        return ('item', len(self._container))
        
    def sizeForDisplay(self):
        """See ISized"""
        num_items = len(self._container)
        if num_items == 1:
            return '1 item'
        return '%s items' % num_items


=== Zope3/src/zope/app/container/configure.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/container/configure.zcml:1.2	Wed Dec 25 09:12:46 2002
+++ Zope3/src/zope/app/container/configure.zcml	Fri Dec 27 13:22:58 2002
@@ -39,6 +39,10 @@
            provides="zope.app.interfaces.container.IZopeContainer"
            for="zope.app.interfaces.container.IContainer" />
 
+  <adapter factory="zope.app.container.size.ContainerSized"
+           provides="zope.app.interfaces.size.ISized"
+           for="zope.app.interfaces.container.IContainer" />
+           
   <event:subscribe 
       subscriber = ".dependency.CheckDependency"
       event_types = "zope.app.interfaces.event.IObjectRemovedEvent"