commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7824 - in trunk/gnue-forms/src: . GFObjects


From: jamest
Subject: [gnue] r7824 - in trunk/gnue-forms/src: . GFObjects
Date: Wed, 10 Aug 2005 22:20:08 -0500 (CDT)

Author: jamest
Date: 2005-08-10 22:20:07 -0500 (Wed, 10 Aug 2005)
New Revision: 7824

Modified:
   trunk/gnue-forms/src/GFForm.py
   trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
changed the query markup from >:value to :>:value
removed references to isSaved per the TODO in the file
some cleanup and docstrings


Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py      2005-08-10 15:05:21 UTC (rev 7823)
+++ trunk/gnue-forms/src/GFForm.py      2005-08-11 03:20:07 UTC (rev 7824)
@@ -503,7 +503,7 @@
 
     # Are there any not yet posted changes in any of the blocks?
     for block in self._logic._blockList:
-      if not block.isSaved():
+      if block.isPending():
         return False
 
     # Does a connection have any pending (already posted but not yet committed)
@@ -531,7 +531,7 @@
         self.commit()
 
       for block in self._logic._blockList:
-        if not block.isSaved():
+        if block.isPending():
           message = _("Data not saved. Save changes or clear the form to "
                       "proceed.")
           return message

Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py   2005-08-10 15:05:21 UTC (rev 
7823)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py   2005-08-11 03:20:07 UTC (rev 
7824)
@@ -24,6 +24,8 @@
 Classes making up the Block object
 """
 
+__revision__ = "$Id$"
+
 from gnue.forms.GFObjects.GFDataSource import GFDataSource
 
 from gnue.common.apps import errors
@@ -31,18 +33,10 @@
 from GFContainer import GFContainer
 from gnue.common import events
 
-import string
-
-# These should really go somewhere else
-TRUE = 1
-FALSE = 0
-
-
-############################################################
-# GFBlock
-#
-#
 class GFBlock(GFContainer, events.EventAware):
+  """
+  Class that represents the <block> tag in a gfd file.
+  """
   def __init__(self, parent=None):
     GFContainer.__init__(self, parent, 'GFBlock')
 
@@ -117,7 +111,9 @@
         'isEmpty':{'function':self.isEmpty,
                     'description':'Returns True if block is empty.'},
         'isSaved':{'function':self.isSaved,
-                    'description':'Returns True if block contains no modified 
records.'},
+                    'description':'Depriciated: Returns True if block contains 
no modified records.'},
+        'isPending':{'function':self.isPending,
+                    'description':'Returns True if block contains modified 
records.'},
         'lastRecord':{'function':self.lastRecord,
                   'description':'Navigates the block to the last record it 
contains.'},
         'nextRecord':{'function':self.nextRecord,
@@ -190,7 +186,7 @@
       del self.__dict__['restrictInsert']
 
     if hasattr(self,'datasource'):
-      self.datasource = string.lower(self.datasource)
+      self.datasource = self.datasource.lower()
 
     return GFContainer._buildObject(self)
 
@@ -342,7 +338,8 @@
     Returns True if the datasource the block is associated
     with is not pending any changes.
     """
-    # TODO: Find all uses of isSaved() and replace with: not isPending()
+    print "DEPRECIATION WARNING: the use of block.isSaved () is depreciated.", 
\
+          "Please use block.isPending () instead."
     return not self.isPending()
 
   def isPending(self):
@@ -387,7 +384,8 @@
       field.gotNewCurrentRecord()
       for entry in field._entryList:
         # This loop is probably better somewhere else
-        entry.recalculateVisible( adjustment, self._currentRecord, 
self._recordCount)
+        entry.recalculateVisible( adjustment, self._currentRecord, 
+                                  self._recordCount)
       self._form.updateUIEntry(field)
       self._form.refreshUIEvents()
 
@@ -443,7 +441,8 @@
       self.processTrigger('PRE-FOCUSIN')
       self.processTrigger('POST-FOCUSIN')
 
-    elif self.autoCreate and not self.isEmpty() and not self.editable in 
('update','N'):
+    elif self.autoCreate and not self.isEmpty() and \
+         not self.editable in ('update','N'):
       self.newRecord()
       # Go to first field
       self._form.findAndChangeFocus(self._entryList[0])
@@ -604,11 +603,11 @@
     # If Enter-Query is hit thrice, cancel the query and go into normal mode.
 
     if self.mode != 'query':
-        self.mode = 'query'
-        self._query2 = int(gConfigForms("RememberLastQuery"))
-        self._queryValues = {}
-        self._queryValues.update(self._queryDefaults)
-        self.switchRecord(0)
+      self.mode = 'query'
+      self._query2 = int(gConfigForms("RememberLastQuery"))
+      self._queryValues = {}
+      self._queryValues.update(self._queryDefaults)
+      self.switchRecord(0)
 
   def copyQuery(self):
     self._query2 = 0
@@ -644,8 +643,10 @@
     # graft in the sloppy query stuff if needed
     for block in maxList:
       for entry in block._entryList:
-        if hasattr(entry._field,'sloppyQuery') and 
block._queryValues.has_key(entry._field):
-          block._queryValues[entry._field] = "%"+ 
string.join(list(block._queryValues[entry._field]),"%")+"%"
+        if hasattr(entry._field,'sloppyQuery') and \
+           block._queryValues.has_key(entry._field):
+          block._queryValues[entry._field] = "%"+ \
+            "%".join(list(block._queryValues[entry._field]))+"%"
 
     # Find root block
     rootBlock = maxList [-1]
@@ -807,17 +808,18 @@
   """
 
   # 'user input': [GCondition, pass value?]
-  comparisons = { '>': ['gt', True],
-                  '>=': ['ge', True],
-                  '<': ['lt', True],
-                  '<=': ['le', True],
-                  '=': ['eq', True],
-                  '!=': ['ne', True],
-                  'like': ['like', True],
-                  'null': ['null', False],
-                  '!null': ['notnull', False],
-                }
-
+  baseComparisons = { '>': ['gt', True],
+                      '>=': ['ge', True],
+                      '<': ['lt', True],
+                      '<=': ['le', True],
+                      '=': ['eq', True],
+                      '!=': ['ne', True],
+                      'like': ['like', True],
+                      'empty': ['null', False],
+                      'notempty': ['notnull', False],
+                    }
+  comparisonDelimeter = ":"
+  
   condLike = {}
   condEq   = {}
   conditions = []
@@ -825,44 +827,49 @@
   for entry, val in block._queryValues.items ():
     if entry._bound and entry.isQueryable () and len (str (val)):
       
-      splitValue = val.split(':')
-      splitValue[0]=splitValue[0].lower()
-      try:
-        if comparisons[splitValue[0]][1]:
-          conditions.append([ comparisons[splitValue[0]][0], 
-                              ['field', entry.field], 
-                              ['const', ':'.join(splitValue[1:])] 
-                            ])
-        else:
-          conditions.append([ comparisons[splitValue[0]][0], 
-                              ['field', entry.field] 
-                            ])
+      # New : operator support
+      match = False
+      for comparison in baseComparisons.keys():
           
-        continue
-      except KeyError:
-        pass
+        if val[:2+len(comparison)].lower() == "%s%s%s" % \
+          (comparisonDelimeter, comparison, comparisonDelimeter):
+          value=val[2+len(comparison):]
+          
+          if baseComparisons[comparison][1]:
+            conditions.append([ baseComparisons[comparison][0], 
+                                ['field', entry.field], 
+                                ['const', value] 
+                              ])
+          else:
+            conditions.append([ baseComparisons[comparison][0], 
+                                ['field', entry.field] 
+                              ])
+          match = True  
+          break
       
       # Falls through to old behaviour if no : condition given or 
       # the : condition is unknown
-      if entry.typecast == 'text':
-        if block._convertAsterisksToPercent:
-          try:
-            val = str (val).replace ('*', '%')
-          except ValueError:
-            pass
-
-        if (val.find ('%') >= 0 or val.find ('_') >= 0):
-          condLike [entry.field] = val
+      if not match:
+        if entry.typecast == 'text':
+          if block._convertAsterisksToPercent:
+            try:
+              val = str (val).replace ('*', '%')
+            except ValueError:
+              pass
+  
+          if (val.find ('%') >= 0 or val.find ('_') >= 0):
+            condLike [entry.field] = val
+          else:
+            condEq [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 or conditions:
-    result = GConditions.buildConditionFromPrefix (['and'] + epf + lpf + 
conditions)
+    result = GConditions.buildConditionFromPrefix (['and'] + epf + 
+                                                   lpf + conditions)
 
   else:
     result = {}
@@ -870,19 +877,12 @@
   return result
 
 
+class _BlockIter:
+  """A simple resultset iterator that lets you use ResultSets as:
 
-
-
-# A simple resultset iterator
-# Lets you use ResultSets as:
-#
-#   for record in myResultSet:
-#      blah
-#
-# NOTE: Python 2.2+  (but it won't get called in
-#    Python 2.1 or below, so not a problem)
-#
-class _BlockIter:
+    for record in myResultSet:
+      blah
+  """
   def __init__(self, block):
     self.block = block
     self.new = True





reply via email to

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