[CMF-checkins] CVS: Products/CMFTopic - ListCriterion.py:1.8.10.1
Tres Seaver
tseaver@zope.com
Mon, 7 Jan 2002 14:34:56 -0500
Update of /cvs-repository/Products/CMFTopic
In directory cvs.zope.org:/tmp/cvs-serv23591/CMFTopic
Modified Files:
Tag: tseaver-listcrit_operator-branch
ListCriterion.py
Log Message:
- Add 'operator' attribute to ListCriterion, to permit overriding the
implicit 'or' operator used for keyword indexes such as 'Subject'.
=== Products/CMFTopic/ListCriterion.py 1.8 => 1.8.10.1 ===
from AccessControl import ClassSecurityInfo
-import string, operator
+import string
class ListCriterion( AbstractCriterion ):
"""
@@ -39,7 +39,7 @@
security = ClassSecurityInfo()
- _editableAttributes = ( 'value', )
+ _editableAttributes = ( 'value', 'operator' )
def __init__( self, id, field ):
self.id = id
@@ -52,6 +52,7 @@
Restore to original value.
"""
self.value = ( '', ) # *Not* '()', which won't do at all!
+ self.operator = None
security.declareProtected( TopicPermissions.ChangeTopics, 'getEditForm' )
def getEditForm( self ):
@@ -62,7 +63,7 @@
return "listc_edit"
security.declareProtected( TopicPermissions.ChangeTopics, 'edit' )
- def edit( self, value=None ):
+ def edit( self, value=None, operator=None ):
"""
Update the value we match against.
"""
@@ -73,6 +74,11 @@
value = string.split( value, '\n' )
self.value = tuple( value )
+ if not operator:
+ operator = None
+
+ self.operator = operator
+
security.declareProtected( CMFCorePermissions.View, 'getCriteriaItems' )
def getCriteriaItems( self ):
"""
@@ -80,8 +86,17 @@
(used by 'Topic.buildQuery()').
"""
# filter out empty strings
- value = tuple( filter( operator.truth, self.value ) )
- return operator.truth( value ) and ( ( self.field, self.value ), ) or ()
+ result = []
+
+ value = tuple( filter( None, self.value ) )
+ if not value:
+ return ()
+ result.append( ( self.field, self.value ), )
+
+ if self.operator is not None:
+ result.append( ( '%s_operator' % self.field, self.operator ) )
+
+ return tuple( result )