Back to index

plone3  3.1.7
AbstractCriterion.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Home of the abstract Criterion base class.
00014 
00015 $Id: AbstractCriterion.py 36457 2004-08-12 15:07:44Z jens $
00016 """
00017 from Acquisition import Implicit
00018 from AccessControl import ClassSecurityInfo
00019 from Persistence import Persistent
00020 from Globals import InitializeClass
00021 from OFS.SimpleItem import Item
00022 
00023 from permissions import AccessContentsInformation
00024 from permissions import ChangeTopics
00025 
00026 
00027 class AbstractCriterion( Persistent, Item, Implicit ):
00028     """
00029         Abstract base class for Criterion objects.
00030     """
00031 
00032     security = ClassSecurityInfo()
00033 
00034     security.declareProtected(ChangeTopics, 'apply')
00035     def apply( self, command ):
00036         """
00037             Apply 'command', which is expected to be a dictionary,
00038             to 'self.edit' (makes using Python Scripts easier).
00039         """
00040         self.edit(**command)
00041 
00042     security.declareProtected( ChangeTopics, 'editableAttributes' )
00043     def editableAttributes( self ):
00044         """
00045             Return a list of editable attributes, used by topics
00046             to build commands to send to the 'edit' command of each
00047             criterion, which may vary.
00048 
00049             Requires concrete subclasses to implement the attribute
00050             '_editableAttributes' which is a tuple of attributes
00051             that can be edited, for example:
00052 
00053             _editableAttributes = ( 'value', 'direction' )
00054         """
00055         return self._editableAttributes
00056 
00057     security.declareProtected( AccessContentsInformation, 'Type' )
00058     def Type( self ):
00059         """
00060             Return the Type of Criterion this object is.  This
00061             method can be overriden in subclasses, or those
00062             concrete subclasses must define the 'meta_type'
00063             attribute.
00064         """
00065         return self.meta_type
00066 
00067     security.declareProtected( AccessContentsInformation, 'Field' )
00068     def Field( self ):
00069         """
00070             Return the field that this criterion searches on.  The
00071             concrete subclasses can override this method, or have
00072             the 'field' attribute.
00073         """
00074         return self.field
00075 
00076     security.declareProtected( AccessContentsInformation, 'Description' )
00077     def Description( self ):
00078         """
00079             Return a brief but helpful description of the Criterion type,
00080             preferably based on the classes __doc__ string.
00081         """
00082         lines = [ line.strip() for line in self.__doc__.splitlines() ]
00083         return ' '.join( [ line for line in lines if line ] )
00084 
00085 InitializeClass( AbstractCriterion )