dabo Commit
Revision 5135
Date: 2009-03-17 11:51:49 -0700 (Tue, 17 Mar 2009)
Author: Pedro.Gato
Trac: http://trac.dabodev.com/changeset/5135

Changed:
U   trunk/dabo/biz/dBizobj.py
U   trunk/dabo/db/dCursorMixin.py
U   trunk/dabo/db/dDataSet.py
U   trunk/dabo/lib/datanav/Page.py

Log:
This makes dBizobj.filter() VirtualField aware, they are handled after the real 
fields, creating a fake filter.
Also modify datanav SelectPage to work with VirtualFields, no changes to user 
code needed, VirtualFields are now treated as any other ordinary field

Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py   2009-03-16 10:39:55 UTC (rev 5134)
+++ trunk/dabo/biz/dBizobj.py   2009-03-17 18:51:49 UTC (rev 5135)
@@ -37,6 +37,10 @@
                # now the DefaultValues property (used to be self.defaultValues 
attribute)
                self._defaultValues = {}
 
+               # PKId's of rows to be filtered out when
+               # filtering Virtual fields
+               self.__filterPKVirtual = []
+
                self._beforeInit()
                self.setConnection(conn)
                # We need to make sure the cursor is created *before* the call 
to
@@ -994,17 +998,67 @@
                        endswith: fld.endswith(expr)
                        contains: expr in fld
                """
-               currPK = self.getPK()
-               self._CurrentCursor.filter(fld=fld, expr=expr, op=op)
-               newPK = self.getPK()
-               if newPK != currPK:
-                       try:
-                               self.moveToPK(currPK)
-                       except dabo.dException.RowNotFoundException:
+               #currPK = self.getPK()
+               if self.VirtualFields.has_key(fld):
+                       self.scan(self.scanVirtualFields, fld=fld, expr=expr, 
op=op, reverse=True)
+                       self._CurrentCursor.filterByExpression("%s IN (%s)" % 
(self.KeyField, ", ".join( "%i" % key for key in self.__filterPKVirtual)))
+
+                       # clear filter id's
+                       self.__filterPKVirtual = []
+               else:
+                       self._CurrentCursor.filter(fld=fld, expr=expr, op=op)
+
+               #try:
+               #       newPK = self.getPK()
+               #except dException.NoRecordsException:
+               #       newPK = currPK
+
+               #if newPK != currPK:
+               #       try:
+               #               self.moveToPK(currPK)
+               #       except dabo.dException.RowNotFoundException:
                                # The old row was filtered out of the dataset
-                               self.first()
+               #               self.first()
 
+       def scanVirtualFields(self, fld, expr, op):
+               virtValue = self.getFieldVal(fld)
 
+               if op.lower() in ("eq", "equals", "="):
+                       if virtValue == expr:
+                               
self.__filterPKVirtual.append(self.getFieldVal(self.KeyField))
+
+               elif op.lower() in ("ne", "nequals", "!="):
+                       if virtValue != expr:
+                               
self.__filterPKVirtual.append(self.getFieldVal(self.KeyField))
+
+               elif op.lower() in ("gt", ">", "greater than"):
+                       if expr > virtValue:
+                               
self.__filterPKVirtual.append(self.getFieldVal(self.KeyField))
+
+               elif op.lower() in ("gte", ">=", "greater than/equal to"):
+                       if expr >= virtValue:
+                               
self.__filterPKVirtual.append(self.getFieldVal(self.KeyField))
+
+               elif op.lower() in ("lt", "<", "less than"):
+                       if expr < virtValue:
+                               
self.__filterPKVirtual.append(self.getFieldVal(self.KeyField))
+
+               elif op.lower() in ("lte", "<=", "less than/equal to"):
+                       if expr <= virtValue:
+                               
self.__filterPKVirtual.append(self.getFieldVal(self.KeyField))
+
+               elif op.lower() in ("starts with", "begins with"):
+                       if virtValue.startswith(expr):
+                               
self.__filterPKVirtual.append(self.getFieldVal(self.KeyField))
+
+               elif op.lower() in ("endswith"):
+                       if virtValue.endswith(expr):
+                               
self.__filterPKVirtual.append(self.getFieldVal(self.KeyField))
+
+               elif op.lower() in ("contains"):
+                       if expr in virtValue:
+                               
self.__filterPKVirtual.append(self.getFieldVal(self.KeyField))
+
        def removeFilter(self):
                """Remove the most recently applied filter."""
                self._CurrentCursor.removeFilter()

Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2009-03-16 10:39:55 UTC (rev 5134)
+++ trunk/dabo/db/dCursorMixin.py       2009-03-17 18:51:49 UTC (rev 5135)
@@ -1180,6 +1180,11 @@
                """Apply a filter to the current records."""
                self._records = self._records.filter(fld=fld, expr=expr, op=op)
 
+       def filterByExpression(self, expr):
+               """Allows you to filter by any expression that would make a
+               valid 'where' clause in SQLite.
+               """
+               self._records = self._records.filterByExpression(expr)
 
        def removeFilter(self):
                """Remove the most recently applied filter."""

Modified: trunk/dabo/db/dDataSet.py
===================================================================
--- trunk/dabo/db/dDataSet.py   2009-03-16 10:39:55 UTC (rev 5134)
+++ trunk/dabo/db/dDataSet.py   2009-03-17 18:51:49 UTC (rev 5135)
@@ -210,6 +210,10 @@
                """Allows you to filter by any expression that would make a
                valid 'where' clause in SQLite.
                """
+               if not self:
+                       # No rows, so nothing to filter
+                       return self
+
                stmnt = "select * from dataset where %s" % (expr)
                ret = self.execute(stmnt)
                ret._sourceDataSet = self

Modified: trunk/dabo/lib/datanav/Page.py
===================================================================
--- trunk/dabo/lib/datanav/Page.py      2009-03-16 10:39:55 UTC (rev 5134)
+++ trunk/dabo/lib/datanav/Page.py      2009-03-17 18:51:49 UTC (rev 5135)
@@ -130,6 +130,7 @@
                # WHERE clause based on user input
                self.selectFields = {}
                self.sortFields = {}
+               self.__virtualFilters = []
                self.sortIndex = 0
        
 
@@ -242,6 +243,10 @@
                flds = self.selectFields.keys()
                whr = ""
                for fld in flds:
+                       if biz.VirtualFields.has_key(fld):
+                               #virtual field, save for later use and ignore
+                               self.__virtualFilters.append(fld)
+                               continue
                        if fld == "limit":
                                # Handled elsewhere
                                continue
@@ -366,6 +371,15 @@
        
                        ret = frm.requery(_fromSelectPage=True)
 
+               if bizobj.RowCount > 0: # don't bother applying this if there 
are no records to work on
+                       # filter virtual fields
+                       for vField in self.__virtualFilters:
+                               opVal = self.selectFields[vField]["op"].Value
+                               ctrl = self.selectFields[vField]["ctrl"]
+
+                               if not _(IGNORE_STRING) in opVal:
+                                       bizobj.filter(vField, ctrl.Value, 
opVal.lower())
+
                if ret:
                        if self.Parent.SelectedPageNumber == 0:
                                # If the select page is active, now make the 
browse page active



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to