vendor/CMF/1.5.5-beta/CMFTopic

view SortCriterion.py @ 0:4341d8feb2f9

Vendor import of CMF 1.5.5-beta
author fguillaume
date Mon, 07 Nov 2005 22:03:41 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """ Allow topic to specify sorting.
15 $Id: SortCriterion.py 36911 2005-04-07 16:38:47Z yuppie $
16 """
17 from Globals import InitializeClass
18 from AccessControl import ClassSecurityInfo
20 from permissions import View
21 from permissions import ChangeTopics
22 from AbstractCriterion import AbstractCriterion
23 from Topic import Topic
24 from interfaces import Criterion
26 class SortCriterion( AbstractCriterion ):
27 """
28 Represent a mock criterion, to allow spelling the sort order
29 and reversal items in a catalog query.
30 """
31 __implements__ = ( Criterion, )
33 meta_type = 'Sort Criterion'
35 security = ClassSecurityInfo()
37 field = None # Don't prevent use of field in other criteria
39 _editableAttributes = ( 'reversed', )
41 def __init__( self, id, index ):
42 self.id = id
43 self.index = index
44 self.reversed = 0
46 # inherit permissions
47 def Field( self ):
48 """
49 Map the stock Criterion interface.
50 """
51 return self.index
53 security.declareProtected( ChangeTopics, 'getEditForm' )
54 def getEditForm( self ):
55 """
56 Return the name of skin method which renders the form
57 used to edit this kind of criterion.
58 """
59 return 'sort_edit'
61 security.declareProtected( ChangeTopics, 'edit' )
62 def edit( self, reversed ):
63 """
64 Update the value we are to match up against.
65 """
66 self.reversed = bool(reversed)
68 security.declareProtected(View, 'getCriteriaItems')
69 def getCriteriaItems( self ):
70 """
71 Return a tuple of query elements to be passed to the catalog
72 (used by 'Topic.buildQuery()').
73 """
74 result = [ ( 'sort_on', self.index ) ]
76 if self.reversed:
77 result.append( ( 'sort_order', 'reverse' ) )
79 return tuple( result )
81 InitializeClass( SortCriterion )
83 # Register as a criteria type with the Topic class
84 Topic._criteriaTypes.append( SortCriterion )