commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8583 - branches/forms-0.5/src/GFObjects


From: johannes
Subject: [gnue] r8583 - branches/forms-0.5/src/GFObjects
Date: Tue, 22 Aug 2006 03:41:22 -0500 (CDT)

Author: johannes
Date: 2006-08-22 03:41:21 -0500 (Tue, 22 Aug 2006)
New Revision: 8583

Modified:
   branches/forms-0.5/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: branches/forms-0.5/src/GFObjects/GFBlock.py
===================================================================
--- branches/forms-0.5/src/GFObjects/GFBlock.py 2006-08-21 21:32:02 UTC (rev 
8582)
+++ branches/forms-0.5/src/GFObjects/GFBlock.py 2006-08-22 08:41:21 UTC (rev 
8583)
@@ -140,7 +140,8 @@
                         'description':'Executes the current query.'},
         'call': {'function'   : self.callFunction,
                  'description': 'Executes a function of the datasource'},
-        'update': {'function': self.updateCurrentRecordSet}
+        'update': {'function': self.updateCurrentRecordSet},
+        'get_data': {'function': self.trigger_get_data}
         }
 
     self._triggerProperties={
@@ -553,7 +554,7 @@
 
     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')
@@ -561,15 +562,16 @@
       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')
         # Move to correct record in grid
         self._form.findAndChangeFocus (self._form._currentEntry)
-        self._form._instance.updateRecordCounter (self._form)
 
+      self._form._instance.updateRecordCounter (self._form)
 
+
   def jumpRecords(self, adjustment):
     targetRecord = self._resultSet.getRecordNumber() + adjustment
 
@@ -602,11 +604,11 @@
     Scrolls the block to the given position.
 
     The record number given in position will become the first visible record.
-    """
-    
-    if position < 0:
-      position = 0
-    elif position > self._resultSet.getRecordCount() - self._rows:
+    """
+    
+    if position < 0:
+      position = 0
+    elif position > self._resultSet.getRecordCount() - self._rows:
       position = self._resultSet.getRecordCount() - self._rows
 
     # First, scroll as far as possible without moving the record pointer
@@ -629,7 +631,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)
 
 
@@ -864,11 +866,48 @@
     else:
       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 settable stuff
   #
+  def trigger_get_data(self, fields):
+      return self.get_data(fields)
+
   def triggerSetAutoCommit(self, value):
     self.autoCommit = not not value # Force boolean
 





reply via email to

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