changeset 9:87087f4f4059

fixed bug with default sort order.
author root@xserve09.mpiwg-berlin.mpg.de
date Thu, 17 Feb 2011 20:18:18 +0100
parents 17b19345d011
children 283c01ebe96e
files ZDBInterfaceFolder.py zpt/editZDBInterfaceFolder.zpt
diffstat 2 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ZDBInterfaceFolder.py	Thu Feb 17 19:25:16 2011 +0100
+++ b/ZDBInterfaceFolder.py	Thu Feb 17 20:18:18 2011 +0100
@@ -26,13 +26,16 @@
     manage_editZDBInterfaceFolderForm=PageTemplateFile('zpt/editZDBInterfaceFolder',globals())
 
     
-    def __init__(self, id, title, connection_id=None, autocommit=False):
+    def __init__(self, id, title, connection_id=None, autocommit=False, default_search='bw'):
         """init"""
         self.id = id
         self.title = title
         # database connection id
         self.connection_id = connection_id
+        # set db connection to autocommit
         self.autocommit = autocommit
+        # default text search mode
+        self.default_search = default_search
 
     def getSQLQuery(self, table, argv):
         """returns dict with SQL query string and args"""
@@ -68,10 +71,10 @@
             elif op == "gt":
                 wheres.append(param + " > %s")
                 args.append(val)
-            elif op == "bw":
+            elif op == "ew":
                 wheres.append(param + " ILIKE %s")
                 args.append("%" + val)
-            elif op == "ew":
+            elif op == "bw":
                 wheres.append(param + " ILIKE %s")
                 args.append(val + "%")
             elif op == "ct":
@@ -96,8 +99,10 @@
 
         # evaluate argv
         for (key, val) in argv.items():
+            logging.debug("process key=%s val=%s"%(key,val))
             if key in processed:
                 # parameter has been processed
+                logging.debug("  key=%s processed"%(key))
                 continue
             
             # beginning of a command should always be "_"
@@ -135,9 +140,10 @@
                 
         # process remaining parameters (without _op)
         for (key, val) in unprocessed.items():
-            param = sqlName(key)
-            # default is begins-with
-            doOp("bw", param, val)
+            if key not in processed:
+                param = sqlName(key)
+                # default operation
+                doOp(self.default_search, param, val)
 
         # join it all
         query = "SELECT %s FROM %s"%(select, table)
@@ -161,16 +167,19 @@
         result = self.executeZSQL(query['query'], query['args'])
         return result
     
-    def manage_editZDBInterfaceFolder(self, title=None, connection_id=None, autocommit=None,
+    def manage_editZDBInterfaceFolder(self, title=None, connection_id=None, autocommit=None, default_search=None,
                      REQUEST=None):
         """Change the object"""
-        logging.debug("editZDBInterfaceFolder title=%s, connection_id=%s, autocommit=%s"%(title,connection_id,autocommit))
+        logging.debug("editZDBInterfaceFolder title=%s, connection_id=%s, autocommit=%s default_search=%s"%(title,connection_id,autocommit,default_search))
         if title is not None:
             self.title = title
             
         if connection_id is not None:
             self.connection_id = connection_id
                 
+        if default_search is not None:
+            self.default_search = default_search
+                
         self.autocommit = (autocommit == "on")
                 
         #checkPermission=getSecurityManager().checkPermission
--- a/zpt/editZDBInterfaceFolder.zpt	Thu Feb 17 19:25:16 2011 +0100
+++ b/zpt/editZDBInterfaceFolder.zpt	Thu Feb 17 20:18:18 2011 +0100
@@ -16,5 +16,11 @@
     <p>
       <input type="checkbox" name="autocommit" tal:attributes="checked here/autocommit"/> autocommit (don't use when you want transactions)
     </p>
+    <p class="form-label">Default search mode</p>
+    <p>
+    <select name="default_search">
+        <option tal:repeat="ds python:['bw','ct','eq']" tal:attributes="value ds; selected python:getattr(here,'default_search','')==ds" tal:content="ds"/>
+    </select>
+    </p>
      <p><input type="submit" value="Change" /></p>
   </form>