commit-gnue
[Top][All Lists]
Advanced

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

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


From: reinhard
Subject: [gnue] r8983 - trunk/gnue-forms/src/GFObjects
Date: Tue, 7 Nov 2006 10:05:55 -0600 (CST)

Author: reinhard
Date: 2006-11-07 10:05:55 -0600 (Tue, 07 Nov 2006)
New Revision: 8983

Modified:
   trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
Added possibility to do a query on block level in a trigger.


Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-11-07 14:57:09 UTC (rev 
8982)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-11-07 16:05:55 UTC (rev 
8983)
@@ -61,10 +61,11 @@
     A block covers all aspects of a form's connection to a data source.
 
     Blocks can be filled with data by using the L{init_query}, L{copy_query},
-    and L{execute_query} methods. Within the result set, blocks maintain a
-    pointer to a current record which can be moved around with the
-    L{first_record}, L{prev_record}, L{next_record}, L{last_record},
-    L{goto_record}, and L{jump_records} methods.
+    and L{execute_query} methods or in a single step with the L{query} method.
+    Within the result set, blocks maintain a pointer to a current record which
+    can be moved around with the L{first_record}, L{prev_record},
+    L{next_record}, L{last_record}, L{goto_record}, and L{jump_records}
+    methods.
 
     Read and write access to the data of the current record (and the
     surrounding records) is possible with the L{get_value} and L{set_value}
@@ -181,6 +182,9 @@
                 'deleteRecord': {'function': self.delete_record},
                 'undeleteRecord': {'function': self.undelete_record},
 
+                # Query
+                'query': {'function': self.query},
+
                 # Other stuff
                 'call': {'function': self.call},
                 'update': {'function': self.update},
@@ -993,7 +997,43 @@
             for field in block._fieldList:
                 field.processTrigger('POST-QUERY')
 
+    # -------------------------------------------------------------------------
 
+    def query(self, *args, **params):
+        """
+        Execute a query and populate the block with its result.
+
+        @param args: zero, one or more condition trees, can be in dictionary
+            format, in prefix notation, or GCondition object trees. Field names
+            in these conditions are passed directly to the backend, i.e. they
+            are database column names. This is useful to create queries of
+            arbitary complexity.
+        @param params: simple query values in the notation C{fieldname=value}
+            where the fieldname is the name of a GFField. This is useful to
+            create straightforward simple queries where the database columns
+            included in the condition have their GFField assigned. This also
+            works for lookup fields.
+        """
+
+        # First, convert the fieldname/value pairs to column/value pairs.
+        cond = {}
+        for (fieldname, value) in params.iteritems():
+            field = self._fieldMap[fieldname]
+            if hasattr(field, 'fk_source'):
+                value = field._allowedValuesReverse.get(value)
+            cond[field.field] = value
+
+        # Then, mix in the conditions given in args.
+        for arg in args:
+            cond = GConditions.combineConditions(cond, arg)
+
+        # Now, do the query.
+        self._dataSourceLink.createResultSet(cond)
+
+        # Everything else (including an update of the UI) will happen via
+        # __ds_resultset_activated()
+
+
     # -------------------------------------------------------------------------
     # Saving and Discarding
     # -------------------------------------------------------------------------





reply via email to

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