commit-gnue
[Top][All Lists]
Advanced

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

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


From: johannes
Subject: [gnue] r8584 - trunk/gnue-forms/src/GFObjects
Date: Tue, 22 Aug 2006 03:48:44 -0500 (CDT)

Author: johannes
Date: 2006-08-22 03:48:43 -0500 (Tue, 22 Aug 2006)
New Revision: 8584

Modified:
   trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
Only access the _block attribute of a GFObject if it is available.
Added a 'get_data' method for exporting the current resultset


Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-08-22 08:41:21 UTC (rev 
8583)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-08-22 08:48:43 UTC (rev 
8584)
@@ -182,7 +182,10 @@
         'description': 'Executes a function of the datasource'},
       'update': {
         'function'   : self.updateCurrentRecordSet,
-        'description': ''}
+        'description': ''},
+      'get_data': {
+        'function': self.trigger_get_data,
+        'description': 'Export current result set into a list of dicts'}
     }
 
     self._triggerProperties = {
@@ -468,7 +471,7 @@
         self.__scrolling = False
     else:
       # If we didn't move the cursor, we have to update cursor position in UI
-      if self._form._currentEntry._block == self:
+      if getattr(self._form._currentEntry, '_block', None) == self:
         self._form.findAndChangeFocus (self._form._currentEntry)
 
 
@@ -772,7 +775,7 @@
       raise "Invalid record number"
 
     if recordNumber != self._resultSet.getRecordNumber ():
-      if self._form._currentEntry._block == self:
+      if getattr(self._form._currentEntry, '_block', None) == self:
         # Focus out
         self.processTrigger ('PRE-FOCUSOUT')
         self.processTrigger ('POST-FOCUSOUT')
@@ -780,7 +783,7 @@
       if not self._resultSet.setRecord (recordNumber):
         self._resultSet.lastRecord ()
 
-      if self._form._currentEntry._block == self:
+      if getattr(self._form._currentEntry, '_block', None) == self:
         # Focus in
         self.processTrigger ('PRE-FOCUSIN')
         self.processTrigger ('POST-FOCUSIN')
@@ -1052,10 +1055,52 @@
       return None
 
 
+  # ---------------------------------------------------------------------------
+  # Get a sequence of dictionaries from the current resultSet
+  # ---------------------------------------------------------------------------
+
+  def get_data(self, fieldnames):
+      """
+      Build a list of dictionaries of the current resultset using the fields
+      defined by fieldnames.
+
+      @param fieldnames: list of fieldnames to export per record
+      @returns: list of dictionaries (one per record)
+      """
+
+      result = []
+      if not fieldnames:
+          fields = self._fieldMap.values()
+      else:
+          fields = [self._fieldMap[fld] for fld in fieldnames]
+
+      for r in self._resultSet:
+          add = {}
+          for field in fields:
+              fname = field.field
+              if hasattr(field, 'fk_source'):
+                  value = field._allowedValues.get(r[fname])
+              else:
+                  value = r[fname]
+
+              add[fname] = value
+
+          result.append(add)
+
+      return result
+
+
   # ===========================================================================
   # Trigger Namespace properties
   # ===========================================================================
 
+  def trigger_get_data(self, fields):
+
+      return self.get_data(fields)
+
+  # ---------------------------------------------------------------------------
+
+
   def triggerSetAutoCommit (self, value):
 
     self.autoCommit = bool (value)





reply via email to

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