[Erp5-report] r18058 - /erp5/trunk/products/ZSQLCatalog/SQLCatalog.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Dec 6 15:41:14 CET 2007


Author: ivan
Date: Thu Dec  6 15:41:13 2007
New Revision: 18058

URL: http://svn.erp5.org?rev=18058&view=rev
Log:
Add rendering of DateTime keys in SQL generation code for queries.

Modified:
    erp5/trunk/products/ZSQLCatalog/SQLCatalog.py

Modified: erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SQLCatalog.py?rev=18058&r1=18057&r2=18058&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SQLCatalog.py (original)
+++ erp5/trunk/products/ZSQLCatalog/SQLCatalog.py Thu Dec  6 15:41:13 2007
@@ -191,6 +191,7 @@
 FULL_TEXT_SEARCH_MODE = 'FullText'
 EXACT_MATCH_SEARCH_MODE = 'ExactMatch'
 KEYWORD_SEARCH_MODE = 'Keyword'
+DATETIME_SEARCH_MODE = 'DateTime'
 
 
 class QueryMixin:
@@ -254,6 +255,7 @@
 
   def asSQLExpression(self, key_alias_dict=None,
                       keyword_search_keys=None,
+                      datetime_search_keys=None,
                       full_text_search_keys=None,
                       ignore_empty_string=1, stat__=0):
     """
@@ -358,6 +360,7 @@
 
   def asSQLExpression(self, key_alias_dict=None,
                             keyword_search_keys=None,
+                            datetime_search_keys=None,
                             full_text_search_keys=None,
                             ignore_empty_string=1, stat__=0):
     """
@@ -425,6 +428,21 @@
                         and isinstance(value, basestring):
           if '%' in value and search_key != EXACT_MATCH_SEARCH_MODE:
             comparison_operator = 'LIKE'
+          elif search_key == DATETIME_SEARCH_MODE  or (
+               datetime_search_keys is not None and key in datetime_search_keys):
+            if len(value) >= 1 and value[0:2] in ('<=','!=','>='):
+              comparison_operator = value[0:2]
+              value = value[2:]
+            elif len(value) >= 1 and value[0] in ('=','>','<'):
+              comparison_operator = value[0]
+              value = value[1:]
+            if comparison_operator is None:
+              comparison_operator = '='
+            # this seems like a DateTime bug!
+            # 2002/02/01 ==>(UTC) 2002-01-31 22:00:00
+            # 2002-02-01 ==>(UTC) 2002-02-01 00:00:00 (!)
+            value = value.replace('-', '/') 
+            value = DateTime(value).toZone('UTC').ISO()
           elif len(value) >= 1 and value[0:2] in ('<=','!=','>='):
             comparison_operator = value[0:2]
             value = value[2:]
@@ -538,6 +556,7 @@
   def asSQLExpression(self, key_alias_dict=None,
                             ignore_empty_string=1,
                             keyword_search_keys=None,
+                            datetime_search_keys=None,
                             full_text_search_keys=None,
                             stat__=0):
     """
@@ -804,6 +823,11 @@
       'type'    : 'multiple selection',
       'select_variable' : 'getColumnIds',
       'mode'    : 'w' },
+    { 'id'      : 'sql_catalog_datetime_search_keys',
+      'description' : 'Columns which should be considered as full text search',
+      'type'    : 'multiple selection',
+      'select_variable' : 'getColumnIds',
+      'mode'    : 'w' },
     { 'id'      : 'sql_catalog_full_text_search_keys',
       'description' : 'Columns which should be considered as full text search',
       'type'    : 'multiple selection',
@@ -864,6 +888,7 @@
   sql_unique_values = ''
   sql_catalog_paths = ''
   sql_catalog_keyword_search_keys =  ()
+  sql_catalog_datetime_search_keys = ()
   sql_catalog_full_text_search_keys = ()
   sql_catalog_request_keys = ()
   sql_search_result_keys = ()
@@ -2116,6 +2141,7 @@
     acceptable_key_map = self.getColumnMap()
     full_text_search_keys = list(self.sql_catalog_full_text_search_keys)
     keyword_search_keys = list(self.sql_catalog_keyword_search_keys)
+    datetime_search_keys = list(self.sql_catalog_datetime_search_keys)
     topic_search_keys = self.sql_catalog_topic_search_keys
     multivalue_keys = self.sql_catalog_multivalue_keys
 
@@ -2386,6 +2412,7 @@
         query_result = query.asSQLExpression(key_alias_dict=key_alias_dict,
                                     full_text_search_keys=full_text_search_keys,
                                     keyword_search_keys=keyword_search_keys,
+                                    datetime_search_keys=datetime_search_keys,
                                     ignore_empty_string=ignore_empty_string,
                                     stat__=stat__)
         if query_result['where_expression'] not in ('',None):
@@ -2714,4 +2741,3 @@
 Globals.default__class_init__(Catalog)
 
 class CatalogError(Exception): pass
-




More information about the Erp5-report mailing list