[Erp5-report] r9111 - in /erp5/trunk/products: ERP5Catalog/tests/ ZSQLCatalog/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Aug 9 17:40:53 CEST 2006


Author: jerome
Date: Wed Aug  9 17:40:38 2006
New Revision: 9111

URL: http://svn.erp5.org?rev=9111&view=rev
Log:
Treat unicode objects as strings in SQLCatalog.buildSQLQuery


Modified:
    erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py
    erp5/trunk/products/ZSQLCatalog/SQLCatalog.py

Modified: erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py?rev=9111&r1=9110&r2=9111&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py (original)
+++ erp5/trunk/products/ERP5Catalog/tests/testERP5Catalog.py Wed Aug  9 17:40:38 2006
@@ -726,4 +726,17 @@
                  module.searchFolder(group_uid=group_nexedi_category.getUid())]
     self.assertEquals(organisation_list, [organisation])
 
-
+  def test_21_SearchingWithUnicode(self, quiet=quiet, run=run_all_test):
+    if not run: return
+    if not quiet:
+      message = 'Test searching with unicode'
+      ZopeTestCase._print('\n%s ' % message)
+      LOG('Testing... ',0,message)
+
+    person_module = self.getPersonModule()
+    person_module.newContent(portal_type='Person', title='A Person')
+    get_transaction().commit()
+    self.tic()
+    self.assertNotEquals([], self.getCatalogTool().searchResults(
+                                          portal_type='Person', title=u'A Person'))
+

Modified: erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SQLCatalog.py?rev=9111&r1=9110&r2=9111&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SQLCatalog.py (original)
+++ erp5/trunk/products/ZSQLCatalog/SQLCatalog.py Wed Aug  9 17:40:38 2006
@@ -1240,7 +1240,7 @@
       # Get the appropriate SQL Method
       method = getattr(self, self.sql_getitem_by_path)
       search_result = method(path = path, uid_only=1)
-      # If not emptyn return first record
+      # If not empty, return first record
       if len(search_result) > 0:
         return search_result[0].uid
       else:
@@ -1468,22 +1468,21 @@
 
       # We must now turn sort_index into
       # a dict with keys as sort keys and values as sort order
-      if type(sort_index) is type('a'):
+      if isinstance(sort_index, basestring):
         sort_index = [(sort_index, so)]
-      elif type(sort_index) is not type(()) and type(sort_index) is not type([]):
+      elif not isinstance(sort_index, (list, tuple)):
         sort_index = None
 
 
       # If sort_index is a dictionnary
       # then parse it and change it
       sort_on = None
-      #LOG('sorting', 0, str(sort_index))
       if sort_index is not None:
         new_sort_index = []
         for sort in sort_index:
-          if len(sort)==2:
-            new_sort_index.append((sort[0],sort[1],None))
-          elif len(sort)==3:
+          if len(sort) == 2:
+            new_sort_index.append((sort[0], sort[1], None))
+          elif len(sort) == 3:
             new_sort_index.append(sort)
         sort_index = new_sort_index
         try:
@@ -1580,7 +1579,7 @@
               # Add table to table dict
               from_table_dict[acceptable_key_map[key][0]] = acceptable_key_map[key][0] # We use catalog by default
             # Default case: variable equality
-            if type(value) is type('') or isinstance(value, DateTime):
+            if isinstance(value, basestring) or isinstance(value, DateTime):
               # For security.
               value = self._quoteSQLString(value)
               if value != '' or not ignore_empty_string:
@@ -1611,7 +1610,7 @@
                   where_expression += ["MATCH %s AGAINST ('%s' %s)" % (key, value, mode)]
                 else:
                   where_expression += ["%s = '%s'" % (key, value)]
-            elif type(value) is type([]) or type(value) is type(()):
+            elif isinstance(value, (list, tuple)):
               # We have to create an OR from tuple or list
               query_item = []
               for value_item in value:
@@ -1639,11 +1638,11 @@
                       query_item += ["%s = '%s'" % (key, value_item)]
               if len(query_item) > 0:
                 where_expression += ['(%s)' % join(query_item, ' OR ')]
-            elif type(value) is type({}):
+            elif isinstance(value, dict):
               # We are in the case of a complex query
               query_item = []
               query_value = value['query']
-              if type(query_value) != type([]) and type(query_value) != type(()) :
+              if not isinstance(query_value, (list, tuple)):
                 query_value = [query_value]
               operator_value = sql_quote(value.get('operator', 'or'))
               range_value = value.get('range')
@@ -1671,10 +1670,10 @@
           elif key in topic_search_keys:
             # ERP5 CPS compatibility
             topic_operator = 'or'
-            if type(value) is type({}):
+            if isinstance(value, dict):
               topic_operator = sql_quote(value.get('operator', 'or'))
               value = value['query']
-            if type(value) is type(''):
+            if isinstance(value, basestring):
               topic_value = [value]
             else:
               topic_value = value # list or tuple
@@ -1718,7 +1717,7 @@
         where_expression = join(where_expression, ' AND ')
 
       limit_expression = kw.get('limit', None)
-      if type(limit_expression) in (type(()), type([])):
+      if isinstance(limit_expression, (list, tuple)):
         limit_expression = '%s,%s' % (limit_expression[0], limit_expression[1])
       elif limit_expression is not None:
         limit_expression = str(limit_expression)




More information about the Erp5-report mailing list