Back to index

plone3  3.1.7
boolean.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """ Topic:
00020 
00021 """
00022 
00023 __author__  = 'Alec Mitchell'
00024 __docformat__ = 'restructuredtext'
00025 __old_name__ = 'Products.ATContentTypes.types.criteria.ATBooleanCriterion'
00026 from Missing import MV
00027 
00028 from Products.CMFCore.permissions import View
00029 from AccessControl import ClassSecurityInfo
00030 
00031 from Products.Archetypes.atapi import Schema
00032 from Products.Archetypes.atapi import BooleanField
00033 from Products.Archetypes.atapi import BooleanWidget
00034 
00035 from Products.ATContentTypes.criteria import registerCriterion
00036 from Products.ATContentTypes.criteria import FIELD_INDICES
00037 from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
00038 from Products.ATContentTypes.permission import ChangeTopics
00039 from Products.ATContentTypes.criteria.base import ATBaseCriterion
00040 from Products.ATContentTypes.criteria.schemata import ATBaseCriterionSchema
00041 
00042 from Products.ATContentTypes import ATCTMessageFactory as _
00043 
00044 ATBooleanCriterionSchema = ATBaseCriterionSchema + Schema((
00045     BooleanField('bool',
00046                 required=1,
00047                 mode="rw",
00048                 write_permission=ChangeTopics,
00049                 default=None,
00050                 widget=BooleanWidget(
00051                     label=_(u'label_boolean_criteria_bool', default=u'Value'),
00052                     description=_(u'help_boolean_criteria_bool',
00053                                   default=u'True or false')
00054                     ),
00055                 ),
00056     ))
00057 
00058 class ATBooleanCriterion(ATBaseCriterion):
00059     """A boolean criterion"""
00060 
00061     __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion, )
00062     security       = ClassSecurityInfo()
00063     schema         = ATBooleanCriterionSchema
00064     meta_type      = 'ATBooleanCriterion'
00065     archetype_name = 'Boolean Criterion'
00066     shortDesc      = 'Boolean (True/False)'
00067 
00068     security.declareProtected(View, 'getCriteriaItems')
00069     def getCriteriaItems(self):
00070         result = []
00071         if self.getBool():
00072             value = [1,True,'1','True']
00073         else:
00074             value = [0,'',False,'0','False', None, (), [], {}, MV]
00075         result.append((self.Field(), value))
00076 
00077         return tuple( result )
00078 
00079 registerCriterion(ATBooleanCriterion, FIELD_INDICES)