[Erp5-report] r25979 - in /erp5/trunk/products/ZSQLCatalog: Query/ SearchKey/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Mar 11 15:04:10 CET 2009
Author: vincent
Date: Wed Mar 11 15:04:10 2009
New Revision: 25979
URL: http://svn.erp5.org?rev=25979&view=rev
Log:
Modify SimpleQuery API to deprecate "operator" parameter in favor of "comparison_operator". Preserve backward compatibility.
Update all callers.
Modified:
erp5/trunk/products/ZSQLCatalog/Query/SimpleQuery.py
erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py
erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py
erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py
erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
Modified: erp5/trunk/products/ZSQLCatalog/Query/SimpleQuery.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/Query/SimpleQuery.py?rev=25979&r1=25978&r2=25979&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/Query/SimpleQuery.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/Query/SimpleQuery.py [utf8] Wed Mar 11 15:04:10 2009
@@ -32,6 +32,7 @@
from Products.ZSQLCatalog.Interface.IQuery import IQuery
from Interface.Verify import verifyClass
from Products.ZSQLCatalog.SQLCatalog import profiler_decorator
+from zLOG import LOG, WARNING
class SimpleQuery(Query):
"""
@@ -39,12 +40,12 @@
one or more values.
"""
@profiler_decorator
- def __init__(self, search_key=None, operator='=', group=None, **kw):
+ def __init__(self, search_key=None, comparison_operator='=', group=None, **kw):
"""
search_key (None, SearchKey instance)
If given, the instance of SearchKey which is responsible for column
map registration and rendering (SQL and SearchText).
- operator (string)
+ comparison_operator (string)
The comparison operator which will be applied between column and
values.
See Operator/ComparisonOperator.py for possible values.
@@ -56,6 +57,10 @@
column name
item value
one or more values
+
+ Deprecated:
+ operator (string)
+ Use comparison_operator instead.
"""
self.search_key = search_key
if len(kw) != 1:
@@ -64,26 +69,32 @@
# Backward compatibility code (those changes should not be needed when
# this Query is instanciated by a SearchKey, as operator should be correct
# already).
- operator = operator.lower()
- if operator == 'in':
+ if len(kw) == 2 and 'operator' in kw:
+ operator = kw.pop('operator')
+ if comparison_operator not in (None, operator):
+ LOG('SimpleQuery', WARNING, 'Both "operator" and "comparison_operator" are provided, ignoring "operator".')
+ else:
+ comparison_operator = operator
+ comparison_operator = comparison_operator.lower()
+ if comparison_operator == 'in':
if isinstance(value, (list, tuple)):
if len(value) == 0:
raise ValueError, 'Empty lists are not allowed.'
elif len(value) == 1:
value = value[0]
- operator = '='
+ comparison_operator = '='
else:
- operator = '='
- elif operator == '=':
+ comparison_operator = '='
+ elif comparison_operator == '=':
if isinstance(value, (list, tuple)):
if len(value) == 0:
raise ValueError, 'Empty lists are not allowed.'
elif len(value) == 1:
value = value[0]
else:
- operator = 'in'
+ comparison_operator = 'in'
self.value = value
- self.operator = operator
+ self.comparison_operator = comparison_operator
self.group = group
@profiler_decorator
@@ -104,7 +115,7 @@
"""
Return an instance of OperatorBase class.
"""
- return sql_catalog.getComparisonOperator(self.operator)
+ return sql_catalog.getComparisonOperator(self.comparison_operator)
def getSearchKey(self, sql_catalog):
"""
@@ -121,7 +132,7 @@
return self.value
def __repr__(self):
- return '<%s %r %s %r>' % (self.__class__.__name__, self.getColumn(), self.operator, self.getValue())
+ return '<%s %r %s %r>' % (self.__class__.__name__, self.getColumn(), self.comparison_operator, self.getValue())
def setGroup(self, group):
self.group = group
Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py?rev=25979&r1=25978&r2=25979&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/DateTimeKey.py [utf8] Wed Mar 11 15:04:10 2009
@@ -139,8 +139,8 @@
append = query_list.append
for value in value_list:
first_date, second_date = getPeriodBoundaries(value)
- append(ComplexQuery([SimpleQuery(search_key=search_key, operator=first_operator, group=group, **{column: first_date}),
- SimpleQuery(search_key=search_key, operator=second_operator, group=group, **{column: second_date})],
+ append(ComplexQuery([SimpleQuery(search_key=search_key, comparison_operator=first_operator, group=group, **{column: first_date}),
+ SimpleQuery(search_key=search_key, comparison_operator=second_operator, group=group, **{column: second_date})],
operator=logical_operator))
return query_list
@@ -156,9 +156,9 @@
comparison_operator = '='
value_list = [castDate(x) for x in value_list]
if logical_operator == 'or' and comparison_operator == '=':
- query_list = [SimpleQuery(search_key=search_key, operator='in', group=group, **{column: value_list})]
- else:
- query_list = [SimpleQuery(search_key=search_key, operator=comparison_operator, group=group, **{column: x}) for x in value_list]
+ query_list = [SimpleQuery(search_key=search_key, comparison_operator='in', group=group, **{column: value_list})]
+ else:
+ query_list = [SimpleQuery(search_key=search_key, comparison_operator=comparison_operator, group=group, **{column: x}) for x in value_list]
return query_list
def getNextPeriod(value):
Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py?rev=25979&r1=25978&r2=25979&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py [utf8] Wed Mar 11 15:04:10 2009
@@ -58,7 +58,7 @@
different_list = []
for value in original_different_list:
if isinstance(value, basestring) and '%' in value:
- result.append(SimpleQuery(search_key=self, group=group, operator='not like', **{column: value}))
+ result.append(SimpleQuery(search_key=self, group=group, comparison_operator='not like', **{column: value}))
else:
different_list.append(value)
if len(different_list):
Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py?rev=25979&r1=25978&r2=25979&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/SearchKey.py [utf8] Wed Mar 11 15:04:10 2009
@@ -324,10 +324,10 @@
append = query_list.append
if logical_operator == 'or' and '=' in operator_value_dict:
# Special case for equality with an 'or' logical operator: use SQL 'in'.
- append(SimpleQuery(search_key=self, operator='in', group=group, **{column: operator_value_dict.pop('=')}))
+ append(SimpleQuery(search_key=self, comparison_operator='in', group=group, **{column: operator_value_dict.pop('=')}))
for comparison_operator, value_list in operator_value_dict.iteritems():
for value in value_list:
- append(SimpleQuery(search_key=self, operator=comparison_operator, group=group, **{column: value}))
+ append(SimpleQuery(search_key=self, comparison_operator=comparison_operator, group=group, **{column: value}))
return query_list
@profiler_decorator
Modified: erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py?rev=25979&r1=25978&r2=25979&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] Wed Mar 11 15:04:10 2009
@@ -60,7 +60,7 @@
return self.column is not None and \
other.getColumn() == self.column and \
other.getValue() == self.value and \
- other.operator == self.operator
+ other.comparison_operator == self.operator
elif isinstance(other, ComplexQuery):
if not (len(other.query_list) == len(self.args) and \
other.logical_operator == self.operator):
@@ -136,7 +136,7 @@
return '%(table_0)s.uid = %(query_table)s.uid AND %(table_0)s.other_uid = %(table_1)s' % kw
def scriptableKeyScript(self, value):
- return SimpleQuery(operator='=', keyword=value)
+ return SimpleQuery(comparison_operator='=', keyword=value)
class TestSQLCatalog(unittest.TestCase):
def setUp(self):
More information about the Erp5-report
mailing list