Back to index

plone3  3.1.7
list.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # ATContentTypes http://plone.org/products/atcontenttypes/
00004 # Archetypes reimplementation of the CMF core types
00005 #
00006 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00007 # Copyright (c) 2003-2006 AT Content Types development team
00008 #
00009 # This software is subject to the provisions of the Zope Public License,
00010 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
00011 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00012 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00013 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00014 # FOR A PARTICULAR PURPOSE
00015 #
00016 ##############################################################################
00017 """ Topic:
00018 
00019 """
00020 
00021 __author__  = 'Christian Heimes <tiran@cheimes.de>'
00022 __docformat__ = 'restructuredtext'
00023 __old_name__ = 'Products.ATContentTypes.types.criteria.ATListCriterion'
00024 
00025 from Products.CMFCore.permissions import View
00026 from AccessControl import ClassSecurityInfo
00027 
00028 from Products.Archetypes.atapi import Schema
00029 from Products.Archetypes.atapi import LinesField
00030 from Products.Archetypes.atapi import StringField
00031 from Products.Archetypes.atapi import SelectionWidget
00032 from Products.Archetypes.atapi import LinesWidget
00033 from Products.Archetypes.atapi import DisplayList
00034 
00035 from Products.ATContentTypes.criteria import registerCriterion
00036 from Products.ATContentTypes.criteria import LIST_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 CompareOperators = DisplayList((
00045                     ('and', _(u'and'))
00046                   , ('or', _(u'or'))
00047     ))
00048 
00049 ATListCriterionSchema = ATBaseCriterionSchema + Schema((
00050     LinesField('value',
00051                 required=1,
00052                 mode="rw",
00053                 write_permission=ChangeTopics,
00054                 accessor="Value",
00055                 mutator="setValue",
00056                 default=[],
00057                 widget=LinesWidget(
00058                     label=_(u'label_list_criteria_value', default=u'Values'),
00059                     description=_(u'help_list_criteria_value',
00060                                   default=u'Values, each on its own line.')
00061                     ),
00062                 ),
00063     StringField('operator',
00064                 required=1,
00065                 mode="rw",
00066                 write_permission=ChangeTopics,
00067                 default='or',
00068                 vocabulary=CompareOperators,
00069                 widget=SelectionWidget(
00070                     label=_(u'label_list_criteria_operator',
00071                             default=u'operator name'),
00072                     description=_(u'help_list_criteria_operator',
00073                                   default=u'Operator used to join the tests on each value.')
00074                     ),
00075                 ),
00076     ))
00077 
00078 class ATListCriterion(ATBaseCriterion):
00079     """A list criterion"""
00080 
00081     __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion, )
00082     security       = ClassSecurityInfo()
00083     schema         = ATListCriterionSchema
00084     meta_type      = 'ATListCriterion'
00085     archetype_name = 'List Criterion'
00086     shortDesc      = 'List of values'
00087 
00088     security.declareProtected(View, 'getCriteriaItems')
00089     def getCriteriaItems(self):
00090         # filter out empty strings
00091         result = []
00092 
00093         value = tuple([ value for value in self.Value() if value ])
00094         if not value:
00095             return ()
00096         result.append((self.Field(), { 'query': value, 'operator': self.getOperator()}),)
00097 
00098         return tuple(result)
00099 
00100 registerCriterion(ATListCriterion, LIST_INDICES)