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

[email protected]
Newsgroups gmane.comp.cms.gnue.cvs
Message-ID <[email protected]>
Author: reinhard
Date: 2007-05-08 09:06:22 -0500 (Tue, 08 May 2007)
New Revision: 9553

Modified:
   trunk/gnue-forms/src/GFForm.py
   trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
Apply filter for all blocks in the form.

issue4 testing


Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py	2007-05-08 13:59:37 UTC (rev 9552)
+++ trunk/gnue-forms/src/GFForm.py	2007-05-08 14:06:22 UTC (rev 9553)
@@ -1492,8 +1492,6 @@
         """
         Applies the filter.
         """
-        if self._currentBlock is None:
-            return
 
         self.endEditing()
 
@@ -1503,17 +1501,29 @@
             self.__rollback_all_connections()
 
             try:
+                for block in self._logic._blockList:
+                    block.processTrigger('PRE-QUERY')
+                    for field in block._fieldMap.itervalues():
+                        field.processTrigger('PRE-QUERY')
+
                 self.__in_filter_mode = False
 
-                self._currentBlock.apply_filter()
+                for block in self._logic._blockList:
+                    block.apply_filter()
 
-            except DBError:
+                for block in self._logic._blockList:
+                    block.processTrigger('POST-QUERY')
+                    for field in block._fieldMap.itervalues():
+                        field.processTrigger('POST-QUERY')
+
+            except Exception:
                 self.__rollback_all_connections()
                 self.__reset_all_blocks()
                 raise
 
         finally:
-            if self._currentBlock.get_record_status() == 'empty':
+            if self._currentBlock is not None \
+                    and self._currentBlock.get_record_status() == 'empty':
                 self.status_message (u_('Query returned no results.'))
             else:
                 self.status_message (u_('Query successful.'))
@@ -1602,7 +1612,7 @@
             # Now do the real commit() on the backend connections (only
             # once per connection, if multiple blocks are sharing the same
             # connection)
-            for connection in self.__get_connections().values():
+            for connection in self.__get_connections().itervalues():
                 connection.commit()
         except:
             # Make sure the block is in consistent state again; this has to
@@ -1667,7 +1677,7 @@
 
     def __rollback_all_connections(self):
 
-        for connection in self.__get_connections().values():
+        for connection in self.__get_connections().itervalues():
             connection.rollback()
 
     # -------------------------------------------------------------------------
@@ -1769,10 +1779,10 @@
         """
 
         result = {}
-        for dLink in self._datasourceDictionary.values():
+        for d_link in self._datasourceDictionary.values():
           try:
-            if dLink._connection is not None:
-              result [dLink.connection] = dLink._connection
+            if d_link._connection is not None:
+              result[d_link.connection] = d_link._connection
           except AttributeError:
             pass
 

Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py	2007-05-08 13:59:37 UTC (rev 9552)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py	2007-05-08 14:06:22 UTC (rev 9553)
@@ -575,62 +575,21 @@
         populated with all records that match the filter criteria.
         """
 
-        # Set the maxList to a single master block as a placeholder.
-        maxList = [self.__get_top_master_block()]
+        self.mode = 'normal'
 
-        # Find the longest master/detail chain that contains filter values. This
-        # will become the chain that is queried.
-        for block in self._logic._blockList:
-            if block.__query_values.keys():
-                templist = [block]
-
-                while (templist[-1]).__get_master_block():
-                    templist.append((templist[-1]).__get_master_block())
-
-                if len(maxList) < len(templist):
-                    maxList = templist
-
         # Store block states
-        for block in self._logic._blockList:
-            block.__last_query_values = {}
-            block.__last_query_values.update(block.__query_values)
+        self.__last_query_values = self.__query_values.copy()
 
-        # Find root block
-        rootBlock = maxList[-1]
+        if self.__get_master_block() is None:
+            # Condition for the master block
+            conditions = self.__generate_condition_tree()
 
-        # Condition for the master block
-        conditions = rootBlock.__generate_conditional()
+            self.__in_query = True
+            try:
+                self._dataSourceLink.createResultSet(conditions)
+            finally:
+                self.__in_query = False
 
-        # Conditions for the detail block
-        for block in maxList[:-1]:
-
-            block.processTrigger('PRE-QUERY')
-            for field in block._fieldMap.itervalues():
-                field.processTrigger('PRE-QUERY')
-
-            c = block.__generate_conditional()
-            exist = GConditions.GCexist()
-            exist.table = block._dataSourceLink.table
-            exist.masterlink = block._dataSourceLink.masterlink
-            exist.detaillink = block._dataSourceLink.detaillink
-            exist._children = [c]
-            conditions = GConditions.combineConditions(conditions, exist)
-
-        for block in self._logic._blockList:
-            block.mode = 'normal'
-
-        # FIXME: This leaves blocks not affected from this filter unupdated
-        self.__in_query = True
-        try:
-            rootBlock._dataSourceLink.createResultSet(conditions)
-        finally:
-            self.__in_query = False
-
-        for block in self._logic._blockList:
-            block.processTrigger('POST-QUERY')
-            for field in block._fieldMap.itervalues():
-                field.processTrigger('POST-QUERY')
-
     # -------------------------------------------------------------------------
 
     def set_filter(self, *args, **params):
@@ -1492,7 +1451,7 @@
     # Create a condition tree
     # -------------------------------------------------------------------------
 
-    def __generate_conditional(self):
+    def __generate_condition_tree(self):
         """
         Create a condition tree based upon the values currently stored in the
         form.
@@ -1601,6 +1560,20 @@
         else:
             result = {}
 
+        if result and self.__get_master_block() is not None:
+            exist = GConditions.GCexist()
+            exist.table = self._dataSourceLink.table
+            exist.masterlink = self._dataSourceLink.masterlink
+            exist.detaillink = self._dataSourceLink.detaillink
+            exist._children = [result]
+            result = exist
+
+        for detail in self._logic._blockList:
+            if detail.__get_master_block() != self:
+                continue
+            result = GConditions.combineConditions(result,
+                    detail.__generate_condition_tree())
+
         return result
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.