dabo Commit
Revision 6897
Date: 2011-10-13 04:08:13 -0700 (Thu, 13 Oct 2011)
Author: Jacekk
Trac: http://trac.dabodev.com/changeset/6897

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

Log:
Added dBizobj.DataSourceName property, corresponding to real source table name 
for business object. If set, the DataSource property acts as an alias.
It allows to create multiple business object with same table as source on 
single form, especially business object can inherit DataSourceName property 
from parent class, while having other properties customized (where, order 
clause, etc.).


Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py   2011-10-12 22:38:59 UTC (rev 6896)
+++ trunk/dabo/biz/dBizobj.py   2011-10-13 11:08:13 UTC (rev 6897)
@@ -36,6 +36,7 @@
                self.__currentCursorKey = None
                # Description of the data represented by this bizobj
                self._dataStructure = None
+               self._dataSource = self._dataSourceName = ""
 
                # Dictionary holding any default values to apply when a new 
record is created. This is
                # now the DefaultValues property (used to be self.defaultValues 
attribute)
@@ -79,7 +80,6 @@
 
                # Various attributes used for Properties
                self._caption = ""
-               self._dataSource = ""
                self._nonUpdateFields = []
                self._scanRestorePosition = True
                self._scanRequeryChildren = True
@@ -1692,7 +1692,7 @@
                                mmPkCol = mmBizobj.KeyField
                        crs = self.createCursor(key=None, 
addToCursorCollection=False)
                        crs._isMM = True
-                       crs.createAssociation(mmBizobj.DataSource, mmPkCol, 
assocTable,
+                       crs.createAssociation(mmBizobj.DataSourceName, mmPkCol, 
assocTable,
                                assocPKColThis, assocPKColOther)
                        self._associations[mmBizobj.DataSource] = {
                                        "bizobj": mmBizobj,
@@ -2461,9 +2461,9 @@
                if self._dataStructure is not None:
                        crs.DataStructure = self._dataStructure
                if not self._RemoteProxy:
-                       crs.Table = self._dataSource
+                       crs.Table = self.DataSourceName
                else:
-                       crs._setTableForRemote(self._dataSource)
+                       crs._setTableForRemote(self.DataSourceName)
                crs.UserSQL = self._userSQL
                crs.VirtualFields = self._virtualFields
                crs.Encoding = self.Encoding
@@ -2565,7 +2565,7 @@
 
        def _getDataSource(self):
                try:
-                       return self._dataSource
+                       return self._dataSource or self._dataSourceName
                except AttributeError:
                        return ""
 
@@ -2574,6 +2574,17 @@
                self._syncWithCursors()
 
 
+       def _getDataSourceName(self):
+               try:
+                       return self._dataSourceName or self._dataSource
+               except AttributeError:
+                       return ""
+
+       def _setDataSourceName(self, val):
+               self._dataSourceName = u"%s" % val
+               self._syncWithCursors()
+
+
        def _getDataStructure(self):
                # We need to save the explicitly-assigned DataStructure here in 
the bizobj,
                # so that we are able to propagate it to any future-assigned 
child cursors.
@@ -2870,7 +2881,7 @@
                        crs = self._sqlMgrCursor = cf.getCursor(cursorClass)
                        crs.setCursorFactory(cf.getCursor, cursorClass)
                        crs.KeyField = self.KeyField
-                       crs.Table = self.DataSource
+                       crs.Table = self.DataSourceName
                        crs.AutoPopulatePK = self.AutoPopulatePK
                        crs.AutoQuoteNames = self.AutoQuoteNames
                        crs.BackendObject = cf.getBackendObject()
@@ -2920,6 +2931,25 @@
        DataSource = property(_getDataSource, _setDataSource, None,
                        _("The title of the cursor. Used in resolving 
DataSource references. (str)"))
 
+       DataSourceName = property(_getDataSourceName, _setDataSourceName, None,
+                       _("""If set, treated as cursor real table name where 
DataSource
+                       is an alias     for it. This allows coexistence of many 
business objects
+                       with same data source on single form. (str)
+                       
+                       Example:
+                               class StockBase(dBizobj):
+                                       def initProperties(self):
+                                               self.DataSourceName = "stock"
+
+                               class StockHigh(StockBase):
+                                       def initProperties(self):
+                                               self.DataSource = "stock_high"
+
+                               class StockLow(StockBase):
+                                       def initProperties(self):
+                                               self.DataSource = "stock_low"
+                       """))
+
        DataStructure = property(_getDataStructure, _setDataStructure, None,
                        _("""Returns the structure of the cursor in a tuple of 
6-tuples.
 

Modified: trunk/dabo/lib/datanav/Page.py
===================================================================
--- trunk/dabo/lib/datanav/Page.py      2011-10-12 22:38:59 UTC (rev 6896)
+++ trunk/dabo/lib/datanav/Page.py      2011-10-13 11:08:13 UTC (rev 6897)
@@ -264,7 +264,7 @@
                        # and dBizobj doesn't define getBaseWhereClause.
                        baseWhere = ""
                biz.setWhereClause(baseWhere)
-               tbl = biz.DataSource
+               tbl = getattr(biz, "DataSourceName", biz.DataSource)
                whr = ""
                for fld in self.selectFields:
                        if fld in biz.VirtualFields:
@@ -284,8 +284,13 @@
                        except (AttributeError, KeyError):
                                table, field = tbl, fld
 
-                       opVal = self.selectFields[fld]["op"].Value
+                       try:
+                               opVal = self.selectFields[fld]["op"].Value
+                       except AttributeError:
+                               # Operator could be Enum type.
+                               opVal = self.selectFields[fld]["op"]
                        opStr = opVal
+                       expJoint = self.selectFields[fld].get("joint", "and")
                        if not QRY_OPERATOR.IGNORE in opVal:
                                fldType = self.selectFields[fld]["type"]
                                ctrl = self.selectFields[fld]["ctrl"]
@@ -380,7 +385,7 @@
                                if useStdFormat:
                                        whr = "%s.%s %s %s" % (table, field, 
opStr, matchStr)
                                if len(whr) > 0:
-                                       biz.addWhere(whr)
+                                       biz.addWhere(whr, expJoint)
                return
 
 
@@ -542,12 +547,12 @@
 
 class EditPage(Page):
        def __init__(self, parent, ds=None, *args, **kwargs):
-               super(EditPage, self).__init__(parent, *args, **kwargs)
                self._focusToControl = None
                self.itemsCreated = False
                self._dataSource = ds
                self.childGrids = []
                self.childrenAdded = False
+               super(EditPage, self).__init__(parent, *args, **kwargs)
                if self.DataSource:
                        self.buildPage()
 



_______________________________________________
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