comparison ZDBInterfaceFolder.py @ 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
comparison
equal deleted inserted replaced
8:17b19345d011 9:87087f4f4059
24 24
25 # management templates 25 # management templates
26 manage_editZDBInterfaceFolderForm=PageTemplateFile('zpt/editZDBInterfaceFolder',globals()) 26 manage_editZDBInterfaceFolderForm=PageTemplateFile('zpt/editZDBInterfaceFolder',globals())
27 27
28 28
29 def __init__(self, id, title, connection_id=None, autocommit=False): 29 def __init__(self, id, title, connection_id=None, autocommit=False, default_search='bw'):
30 """init""" 30 """init"""
31 self.id = id 31 self.id = id
32 self.title = title 32 self.title = title
33 # database connection id 33 # database connection id
34 self.connection_id = connection_id 34 self.connection_id = connection_id
35 # set db connection to autocommit
35 self.autocommit = autocommit 36 self.autocommit = autocommit
37 # default text search mode
38 self.default_search = default_search
36 39
37 def getSQLQuery(self, table, argv): 40 def getSQLQuery(self, table, argv):
38 """returns dict with SQL query string and args""" 41 """returns dict with SQL query string and args"""
39 logging.debug("getSQLquery table=%s argv=%s"%(table,argv)) 42 logging.debug("getSQLquery table=%s argv=%s"%(table,argv))
40 args = [] 43 args = []
66 wheres.append(param + " < %s") 69 wheres.append(param + " < %s")
67 args.append(val) 70 args.append(val)
68 elif op == "gt": 71 elif op == "gt":
69 wheres.append(param + " > %s") 72 wheres.append(param + " > %s")
70 args.append(val) 73 args.append(val)
71 elif op == "bw": 74 elif op == "ew":
72 wheres.append(param + " ILIKE %s") 75 wheres.append(param + " ILIKE %s")
73 args.append("%" + val) 76 args.append("%" + val)
74 elif op == "ew": 77 elif op == "bw":
75 wheres.append(param + " ILIKE %s") 78 wheres.append(param + " ILIKE %s")
76 args.append(val + "%") 79 args.append(val + "%")
77 elif op == "ct": 80 elif op == "ct":
78 wheres.append(param + " ILIKE %s") 81 wheres.append(param + " ILIKE %s")
79 args.append("%" + val + "%") 82 args.append("%" + val + "%")
94 97
95 return 98 return
96 99
97 # evaluate argv 100 # evaluate argv
98 for (key, val) in argv.items(): 101 for (key, val) in argv.items():
102 logging.debug("process key=%s val=%s"%(key,val))
99 if key in processed: 103 if key in processed:
100 # parameter has been processed 104 # parameter has been processed
105 logging.debug(" key=%s processed"%(key))
101 continue 106 continue
102 107
103 # beginning of a command should always be "_" 108 # beginning of a command should always be "_"
104 if key[0] == "-": 109 if key[0] == "-":
105 key = "_" + key[1:] 110 key = "_" + key[1:]
133 # parameter=value pair 138 # parameter=value pair
134 unprocessed[key] = val 139 unprocessed[key] = val
135 140
136 # process remaining parameters (without _op) 141 # process remaining parameters (without _op)
137 for (key, val) in unprocessed.items(): 142 for (key, val) in unprocessed.items():
138 param = sqlName(key) 143 if key not in processed:
139 # default is begins-with 144 param = sqlName(key)
140 doOp("bw", param, val) 145 # default operation
146 doOp(self.default_search, param, val)
141 147
142 # join it all 148 # join it all
143 query = "SELECT %s FROM %s"%(select, table) 149 query = "SELECT %s FROM %s"%(select, table)
144 if wheres: 150 if wheres:
145 query += " WHERE " + (" " + whereOp + " ").join(wheres) 151 query += " WHERE " + (" " + whereOp + " ").join(wheres)
159 """returns result set from search""" 165 """returns result set from search"""
160 query = self.getSQLQuery(_table, argv) 166 query = self.getSQLQuery(_table, argv)
161 result = self.executeZSQL(query['query'], query['args']) 167 result = self.executeZSQL(query['query'], query['args'])
162 return result 168 return result
163 169
164 def manage_editZDBInterfaceFolder(self, title=None, connection_id=None, autocommit=None, 170 def manage_editZDBInterfaceFolder(self, title=None, connection_id=None, autocommit=None, default_search=None,
165 REQUEST=None): 171 REQUEST=None):
166 """Change the object""" 172 """Change the object"""
167 logging.debug("editZDBInterfaceFolder title=%s, connection_id=%s, autocommit=%s"%(title,connection_id,autocommit)) 173 logging.debug("editZDBInterfaceFolder title=%s, connection_id=%s, autocommit=%s default_search=%s"%(title,connection_id,autocommit,default_search))
168 if title is not None: 174 if title is not None:
169 self.title = title 175 self.title = title
170 176
171 if connection_id is not None: 177 if connection_id is not None:
172 self.connection_id = connection_id 178 self.connection_id = connection_id
179
180 if default_search is not None:
181 self.default_search = default_search
173 182
174 self.autocommit = (autocommit == "on") 183 self.autocommit = (autocommit == "on")
175 184
176 #checkPermission=getSecurityManager().checkPermission 185 #checkPermission=getSecurityManager().checkPermission
177 REQUEST.RESPONSE.redirect('manage_main') 186 REQUEST.RESPONSE.redirect('manage_main')