Back to index

plone3  3.1.7
sort.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 
00024 __author__  = 'Christian Heimes <tiran@cheimes.de>'
00025 __docformat__ = 'restructuredtext'
00026 __old_name__ = 'Products.ATContentTypes.types.criteria.ATSortCriterion'
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 SORT_INDICES
00037 from Products.ATContentTypes.interfaces import IATTopicSortCriterion
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 ATSortCriterionSchema = ATBaseCriterionSchema + Schema((
00045     BooleanField('reversed',
00046                 required=0,
00047                 mode="rw",
00048                 write_permission=ChangeTopics,
00049                 default=0,
00050                 widget=BooleanWidget(label=_(u'Reverse')),
00051                 ),
00052 
00053     ))
00054 
00055 class ATSortCriterion(ATBaseCriterion):
00056     """A sort criterion"""
00057 
00058     __implements__ = ATBaseCriterion.__implements__ + (IATTopicSortCriterion, )
00059     security       = ClassSecurityInfo()
00060     schema         = ATSortCriterionSchema
00061     meta_type      = 'ATSortCriterion'
00062     archetype_name = 'Sort Criterion'
00063     shortDesc      = 'Sort'
00064 
00065     security.declareProtected(View, 'getCriteriaItems')
00066     def getCriteriaItems(self):
00067         result = [('sort_on', self.Field())]
00068 
00069         if self.getReversed():
00070             result.append(('sort_order', 'reverse'))
00071 
00072         return tuple(result)
00073 
00074 registerCriterion(ATSortCriterion, SORT_INDICES)