[Erp5-report] r25817 - in /erp5/trunk/products/ZSQLCatalog: Operator/ SearchKey/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Mar 3 13:01:10 CET 2009


Author: vincent
Date: Tue Mar  3 13:01:09 2009
New Revision: 25817

URL: http://svn.erp5.org?rev=25817&view=rev
Log:
Define a new "not like" operator.
Generate automaticaly "not like" operator use in KeywordKey when given operator is "!=" and value contains at least one "%".
Update test to chekc for "not like" operator.

Modified:
    erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py
    erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py
    erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py

Modified: erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py?rev=25817&r1=25816&r2=25817&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py [utf8] Tue Mar  3 13:01:09 2009
@@ -138,6 +138,7 @@
   '<=': MonovaluedComparisonOperator('<='),
   '>=': MonovaluedComparisonOperator('>='),
   'like': MonovaluedComparisonOperator('like'),
+  'not like': MonovaluedComparisonOperator('not like', '!='),
   'match': MatchComparisonOperator('match'),
   'match_boolean': MatchComparisonOperator('match_boolean', mode=' IN BOOLEAN MODE'),
   'match_expansion': MatchComparisonOperator('match_expansion', mode=' WITH QUERY EXPANSION'),

Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py?rev=25817&r1=25816&r2=25817&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/KeywordKey.py [utf8] Tue Mar  3 13:01:09 2009
@@ -32,6 +32,7 @@
 from Products.ZSQLCatalog.SearchText import parse
 from Products.ZSQLCatalog.Interface.ISearchKey import ISearchKey
 from Interface.Verify import verifyClass
+from Products.ZSQLCatalog.Query.SimpleQuery import SimpleQuery
 
 class KeywordKey(SearchKey):
   """
@@ -44,5 +45,25 @@
   def parseSearchText(self, value):
     return parse(value)
 
+  def _buildQuery(self, operator_value_dict, logical_operator, parsed, group):
+    """
+      Treat "!=" operator specialy:
+       - if the value contains at least one "%", change operator into "not like"
+       - otherwise, let it go untouched
+    """
+    result = []
+    if '!=' in operator_value_dict:
+      column = self.getColumn()
+      original_different_list = operator_value_dict.pop('!=')
+      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}))
+        else:
+          different_list.append(value)
+        if len(different_list):
+          operator_value_dict['!='] = different_list
+    return result + SearchKey._buildQuery(self, operator_value_dict, logical_operator, parsed, group)
+
 verifyClass(ISearchKey, KeywordKey)
 

Modified: erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py?rev=25817&r1=25816&r2=25817&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] Tue Mar  3 13:01:09 2009
@@ -289,9 +289,7 @@
                    {column: '"a b"'})
       self.catalog(ReferenceQuery(ReferenceQuery(operator='!=', keyword='a'), operator='and'),
                    {column: '!=a'})
-      self.catalog(ReferenceQuery(
-                     ReferenceQuery(ReferenceQuery(operator='like', keyword='%a'), operator='not')
-                   , operator='and'),
+      self.catalog(ReferenceQuery(ReferenceQuery(operator='not like', keyword='%a'), operator='and'),
                    {column: '!=%a'})
       self.catalog(ReferenceQuery(ReferenceQuery(operator='like', keyword='%a'), operator='and'),
                    {column: '%a'})




More information about the Erp5-report mailing list