Back to index

plone3  3.1.7
SimpleStringCriterion.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 """ Simple string-matching criterion class
00014 
00015 $Id: SimpleStringCriterion.py 77186 2007-06-28 19:06:19Z yuppie $
00016 """
00017 
00018 from AccessControl import ClassSecurityInfo
00019 from Globals import InitializeClass
00020 from zope.interface import implements
00021 
00022 from AbstractCriterion import AbstractCriterion
00023 from interfaces import Criterion as z2ICriterion
00024 from interfaces import ICriterion
00025 from permissions import ChangeTopics
00026 from permissions import View
00027 from Topic import Topic
00028 
00029 
00030 class SimpleStringCriterion( AbstractCriterion ):
00031 
00032     """ Represent a simple field-match for a string value.
00033     """
00034 
00035     implements(ICriterion)
00036     __implements__ = z2ICriterion
00037 
00038     meta_type = 'String Criterion'
00039 
00040     security = ClassSecurityInfo()
00041 
00042     _editableAttributes = ( 'value', )
00043 
00044     def __init__(self, id, field):
00045         self.id = id
00046         self.field = field
00047         self.value = ''
00048 
00049     security.declareProtected( ChangeTopics, 'getEditForm' )
00050     def getEditForm( self ):
00051         """
00052             Return the skinned name of the edit form.
00053         """
00054         return 'ssc_edit'
00055 
00056     security.declareProtected( ChangeTopics, 'edit' )
00057     def edit( self, value ):
00058         """
00059             Update the value we are to match up against.
00060         """
00061         self.value = str( value )
00062 
00063     security.declareProtected(View, 'getCriteriaItems')
00064     def getCriteriaItems( self ):
00065         """
00066             Return a sequence of criteria items, used by Topic.buildQuery.
00067         """
00068         result = []
00069 
00070         if self.value is not '':
00071             result.append( ( self.field, self.value ) )
00072 
00073         return tuple( result )
00074 
00075 InitializeClass( SimpleStringCriterion )
00076 
00077 # Register as a criteria type with the Topic class
00078 Topic._criteriaTypes.append( SimpleStringCriterion )