commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r7288 - trunk/gnue-forms/src/GFObjects


From: johannes
Subject: [gnue] r7288 - trunk/gnue-forms/src/GFObjects
Date: Fri, 1 Apr 2005 08:16:13 -0600 (CST)

Author: johannes
Date: 2005-04-01 08:16:12 -0600 (Fri, 01 Apr 2005)
New Revision: 7288

Modified:
   trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
Use a cleaner way to combine conditions


Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py   2005-04-01 14:15:15 UTC (rev 
7287)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py   2005-04-01 14:16:12 UTC (rev 
7288)
@@ -779,52 +779,54 @@
 
 
 
-#
-# _generateConditional
-#
-# Creates a GCondtional tree based upon the values currently
-# stored in the form.
-#
-def _generateConditional(block):
-    conditionLike = {}
-    conditionEq = {}
-    # Get all the user-supplied parameters from the entry widgets
-    for entry, val in block._queryValues.items():
-        if entry._bound and entry.isQueryable() and len(str(val)):
-          if entry.typecast == 'text':
-            if block._convertAsterisksToPercent:
-              try:
-                val = str(val).replace('*','%')
-              except ValueError:
-                pass
-            if (val.find('%') >= 0 or val.find('_') >= 0):
-              conditionLike[entry.field] = val
-            else:
-              conditionEq[entry.field] = val
-          else:
-            conditionEq[entry.field] = val
+# -----------------------------------------------------------------------------
+# Create a condition tree for a given block
+# -----------------------------------------------------------------------------
 
-    if len(conditionLike.keys()) and len(conditionEq.keys()):
-##        GDebug.printMesg(5,'Combining like w/and (%s, %s)' % (conditionLike, 
conditionEq))
-        conditions = GConditions.combineConditions( \
-            GConditions.buildConditionFromDict(conditionLike, 
GConditions.GClike), \
-            GConditions.buildConditionFromDict(conditionEq, GConditions.GCeq) )
+def _generateConditional (block):
+  """
+  Create a condition tree based upon the values currently stored in the form.
 
-    elif len(conditionLike.keys()):
-        conditions = GConditions.buildConditionFromDict(conditionLike, 
GConditions.GClike)
+  @param block: GFBlock instance to create a condition for
+  @return: GCondition instance with the condition to use or an empty dictionary
+      if no condition is needed.
+  """
 
-    elif len(conditionEq.keys()):
-        conditions = GConditions.buildConditionFromDict(conditionEq, 
GConditions.GCeq)
+  condLike = {}
+  condEq   = {}
 
-    else:
-        conditions = {}
+  # Get all the user-supplied parameters from the entry widgets
+  for entry, val in block._queryValues.items ():
+    if entry._bound and entry.isQueryable () and len (str (val)):
+      if entry.typecast == 'text':
+        if block._convertAsterisksToPercent:
+          try:
+            val = str (val).replace ('*', '%')
+          except ValueError:
+            pass
 
-    return conditions
+        if (val.find ('%') >= 0 or val.find ('_') >= 0):
+          condLike [entry.field] = val
+        else:
+          condEq [entry.field] = val
+      else:
+        condEq [entry.field] = val
 
+  epf = [['eq', ['field', f], ['const', v]] for (f, v) in condEq.items ()]
+  lpf = [['like', ['field', f], ['const', v]] for (f, v) in condLike.items ()]
 
+  if epf or lpf:
+    result = GConditions.buildConditionFromPrefix (['and'] + epf + lpf)
 
+  else:
+    result = {}
 
+  return result
 
+
+
+
+
 # A simple resultset iterator
 # Lets you use ResultSets as:
 #





reply via email to

[Prev in Thread] Current Thread [Next in Thread]