Changeset 2960
- Timestamp:
- 03/23/07 15:40:35 (1 year ago)
- Files:
-
- branches/carl2/INSTALL (modified) (1 diff)
- branches/carl2/dabo/__init__.py (modified) (1 diff)
- branches/carl2/dabo/biz/dBizobj.py (modified) (34 diffs)
- branches/carl2/dabo/biz/test/test_dBizobj.py (modified) (10 diffs)
- branches/carl2/dabo/dApp.py (modified) (10 diffs)
- branches/carl2/dabo/dBug.py (modified) (2 diffs)
- branches/carl2/dabo/dColors.py (modified) (7 diffs)
- branches/carl2/dabo/dEvents.py (modified) (2 diffs)
- branches/carl2/dabo/dException.py (modified) (3 diffs)
- branches/carl2/dabo/dObject.py (modified) (7 diffs)
- branches/carl2/dabo/dPref.py (modified) (4 diffs)
- branches/carl2/dabo/dSecurityManager.py (modified) (1 diff)
- branches/carl2/dabo/dUserSettingProvider.py (modified) (6 diffs)
- branches/carl2/dabo/db/dBackend.py (modified) (13 diffs)
- branches/carl2/dabo/db/dConnectInfo.py (modified) (3 diffs)
- branches/carl2/dabo/db/dConnection.py (modified) (3 diffs)
- branches/carl2/dabo/db/dCursorMixin.py (modified) (59 diffs)
- branches/carl2/dabo/db/dbFirebird.py (modified) (3 diffs)
- branches/carl2/dabo/db/dbMsSQL.py (modified) (1 diff)
- branches/carl2/dabo/db/dbMySQL.py (modified) (5 diffs)
- branches/carl2/dabo/db/dbPostgreSQL.py (modified) (2 diffs)
- branches/carl2/dabo/db/dbSQLite.py (modified) (9 diffs)
- branches/carl2/dabo/db/test/test_dConnectInfo.py (copied) (copied from trunk/dabo/db/test/test_dConnectInfo.py)
- branches/carl2/dabo/db/test/test_dConnection.py (copied) (copied from trunk/dabo/db/test/test_dConnection.py)
- branches/carl2/dabo/db/test/test_dCursorMixin.py (modified) (8 diffs)
- branches/carl2/dabo/lib/DesignerUtils.py (modified) (1 diff)
- branches/carl2/dabo/lib/DesignerXmlConverter.py (modified) (14 diffs)
- branches/carl2/dabo/lib/EasyDialogBuilder.py (modified) (4 diffs)
- branches/carl2/dabo/lib/datanav/Form.py (modified) (1 diff)
- branches/carl2/dabo/lib/datanav/Page.py (modified) (2 diffs)
- branches/carl2/dabo/lib/datanav2/Form.py (modified) (2 diffs)
- branches/carl2/dabo/lib/datanav2/Grid.py (modified) (5 diffs)
- branches/carl2/dabo/lib/datanav2/Page.py (modified) (2 diffs)
- branches/carl2/dabo/lib/dates.py (modified) (3 diffs)
- branches/carl2/dabo/lib/logger.py (modified) (2 diffs)
- branches/carl2/dabo/lib/propertyHelperMixin.py (modified) (2 diffs)
- branches/carl2/dabo/lib/test/test_dates.py (modified) (1 diff)
- branches/carl2/dabo/lib/utils.py (modified) (2 diffs)
- branches/carl2/dabo/lib/xmltodict.py (modified) (6 diffs)
- branches/carl2/dabo/ui/__init__.py (modified) (1 diff)
- branches/carl2/dabo/ui/dDataControlMixinBase.py (modified) (9 diffs)
- branches/carl2/dabo/ui/dPemMixinBase.py (modified) (5 diffs)
- branches/carl2/dabo/ui/dialogs/htmlAbout.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/__init__.py (modified) (16 diffs)
- branches/carl2/dabo/ui/uiwx/dBaseMenuBar.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dBitmap.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dBitmapButton.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dBorderSizer.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dBox.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dButton.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dCalendar.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dCheckBox.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dCheckListBox.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dComboBox.py (modified) (3 diffs)
- branches/carl2/dabo/ui/uiwx/dControlItemMixin.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dDataControlMixin.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dDateTextBox.py (modified) (29 diffs)
- branches/carl2/dabo/ui/uiwx/dDialog.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dDropdownList.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dEditBox.py (modified) (4 diffs)
- branches/carl2/dabo/ui/uiwx/dEditableList.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dEditor.py (modified) (3 diffs)
- branches/carl2/dabo/ui/uiwx/dFileDialog.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dFoldPanelBar.py (modified) (5 diffs)
- branches/carl2/dabo/ui/uiwx/dForm.py (modified) (20 diffs)
- branches/carl2/dabo/ui/uiwx/dFormMain.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dFormMixin.py (modified) (18 diffs)
- branches/carl2/dabo/ui/uiwx/dGauge.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dGlWindow.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dGrid.py (modified) (16 diffs)
- branches/carl2/dabo/ui/uiwx/dGridSizer.py (modified) (4 diffs)
- branches/carl2/dabo/ui/uiwx/dHtmlBox.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dHyperLink.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dImage.py (modified) (7 diffs)
- branches/carl2/dabo/ui/uiwx/dImageMixin.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dLabel.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dLine.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dListBox.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dListControl.py (modified) (5 diffs)
- branches/carl2/dabo/ui/uiwx/dMenu.py (modified) (6 diffs)
- branches/carl2/dabo/ui/uiwx/dMessageBox.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dPageFrame.py (modified) (3 diffs)
- branches/carl2/dabo/ui/uiwx/dPanel.py (modified) (6 diffs)
- branches/carl2/dabo/ui/uiwx/dPemMixin.py (modified) (30 diffs)
- branches/carl2/dabo/ui/uiwx/dRadioGroup.py (deleted)
- branches/carl2/dabo/ui/uiwx/dRadioList.py (modified) (5 diffs)
- branches/carl2/dabo/ui/uiwx/dSizer.py (modified) (3 diffs)
- branches/carl2/dabo/ui/uiwx/dSizerMixin.py (modified) (7 diffs)
- branches/carl2/dabo/ui/uiwx/dSlider.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dSpinner.py (modified) (3 diffs)
- branches/carl2/dabo/ui/uiwx/dSplitter.py (modified) (8 diffs)
- branches/carl2/dabo/ui/uiwx/dStatusBar.py (modified) (1 diff)
- branches/carl2/dabo/ui/uiwx/dTextBox.py (modified) (12 diffs)
- branches/carl2/dabo/ui/uiwx/dToggleButton.py (modified) (2 diffs)
- branches/carl2/dabo/ui/uiwx/dToolBar.py (modified) (18 diffs)
- branches/carl2/dabo/ui/uiwx/dTreeView.py (modified) (18 diffs)
- branches/carl2/dabo/ui/uiwx/gtkProblems (copied) (copied from trunk/dabo/ui/uiwx/gtkProblems)
- branches/carl2/dabo/ui/uiwx/gtkProblems/frame_position_reset.py (copied) (copied from trunk/dabo/ui/uiwx/gtkProblems/frame_position_reset.py)
- branches/carl2/dabo/ui/uiwx/test (copied) (copied from trunk/dabo/ui/uiwx/test)
- branches/carl2/dabo/ui/uiwx/test/test_dEditBox.py (copied) (copied from trunk/dabo/ui/uiwx/test/test_dEditBox.py)
- branches/carl2/dabo/ui/uiwx/test/test_dForm.py (copied) (copied from trunk/dabo/ui/uiwx/test/test_dForm.py)
- branches/carl2/dabo/ui/uiwx/test/test_dTextBox.py (copied) (copied from trunk/dabo/ui/uiwx/test/test_dTextBox.py)
- branches/carl2/dabo/ui/uiwx/uiApp.py (modified) (5 diffs)
- branches/carl2/tests (copied) (copied from trunk/tests)
- branches/carl2/tests/ModuleInitTemplate.py (copied) (copied from trunk/tests/ModuleInitTemplate.py)
- branches/carl2/tests/TestCaseTemplate.py (copied) (copied from trunk/tests/TestCaseTemplate.py)
- branches/carl2/tests/unitTests (copied) (copied from trunk/tests/unitTests)
- branches/carl2/tests/unitTests/CoverageReport.py (copied) (copied from trunk/tests/unitTests/CoverageReport.py)
- branches/carl2/tests/unitTests/Test_dColors.py (copied) (copied from trunk/tests/unitTests/Test_dColors.py)
- branches/carl2/tests/unitTests/Test_dObject.py (copied) (copied from trunk/tests/unitTests/Test_dObject.py)
- branches/carl2/tests/unitTests/biz (copied) (copied from trunk/tests/unitTests/biz)
- branches/carl2/tests/unitTests/biz/__init__.py (copied) (copied from trunk/tests/unitTests/biz/__init__.py)
- branches/carl2/tests/unitTests/db (copied) (copied from trunk/tests/unitTests/db)
- branches/carl2/tests/unitTests/db/__init__.py (copied) (copied from trunk/tests/unitTests/db/__init__.py)
- branches/carl2/tests/unitTests/lib (copied) (copied from trunk/tests/unitTests/lib)
- branches/carl2/tests/unitTests/lib/__init__.py (copied) (copied from trunk/tests/unitTests/lib/__init__.py)
- branches/carl2/tests/unitTests/masterTestSuite.py (copied) (copied from trunk/tests/unitTests/masterTestSuite.py)
- branches/carl2/tests/unitTests/ui (copied) (copied from trunk/tests/unitTests/ui)
- branches/carl2/tests/unitTests/ui/UIwx (copied) (copied from trunk/tests/unitTests/ui/UIwx)
- branches/carl2/tests/unitTests/ui/UIwx/Test_dTextBox.py (copied) (copied from trunk/tests/unitTests/ui/UIwx/Test_dTextBox.py)
- branches/carl2/tests/unitTests/ui/UIwx/__init__.py (copied) (copied from trunk/tests/unitTests/ui/UIwx/__init__.py)
- branches/carl2/tests/unitTests/ui/__init__.py (copied) (copied from trunk/tests/unitTests/ui/__init__.py)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/carl2/INSTALL
r2412 r2960 2 2 3 3 PREREQUISITES: 4 + Python (we recommend the latest, currently 2.4.x) 4 + Python (we recommend the latest, currently 2.5) 5 + sqlite3 (comes with Python 2.5) or pysqlite2 (install separately) 6 + wxPython UNICODE BUILD (we recommend the latest, currently 2.8) 5 7 + MySQLdb (to run the demos) 6 + wxPython (we recommend the latest, currently 2.6.x)7 8 + reportlab 9 + PIL (also known as Imaging or the Python Imaging Library) 8 10 9 11 INSTALLATION: branches/carl2/dabo/__init__.py
r2636 r2960 130 130 errorLog.Caption = "Dabo Error Log" 131 131 errorLog.LogObject = sys.stderr 132 # This log is set to None by default. It must be manually activated 133 # via the Application object. 134 dbActivityLog = Log() 135 dbActivityLog.Caption = "Database Activity Log" 136 dbActivityLog.LogObject = None 132 137 133 138 # Import global settings (do this first, as other imports may rely on it): branches/carl2/dabo/biz/dBizobj.py
r2748 r2960 32 32 33 33 self._beforeInit() 34 self._conn = conn 35 36 super(dBizobj, self).__init__(properties=properties, *args, **kwargs) 37 38 cn = self._conn 39 if cn: 34 cf = self._cursorFactory = conn 35 if cf: 40 36 # Base cursor class : the cursor class from the db api 41 self.dbapiCursorClass = c n.getDictCursorClass()37 self.dbapiCursorClass = cf.getDictCursorClass() 42 38 43 39 # If there are any problems in the createCursor process, an … … 45 41 self.createCursor() 46 42 47 48 43 # We need to make sure the cursor is created *before* the call to 49 44 # initProperties() 50 45 self._initProperties() 46 super(dBizobj, self).__init__(properties=properties, *args, **kwargs) 51 47 self._afterInit() 52 48 self.__att_try_setFieldVal = True … … 56 52 # Cursor to manage SQL Builder info. 57 53 self._sqlMgrCursor = None 58 self._c onn= None54 self._cursorFactory = None 59 55 self.__params = () # tuple of params to be merged with the sql in the cursor 60 56 self.__children = [] # Collection of child bizobjs … … 67 63 self._linkField = "" 68 64 self._parentLinkField = "" 69 # Used the the addChildByRelationDict() method to eliminate infinite loops65 # Used the the _addChildByRelationDict() method to eliminate infinite loops 70 66 self.__relationDictSet = False 71 67 # Do we try to same on the same record during a requery? … … 79 75 self._parent = None 80 76 self._autoPopulatePK = True 77 self._autoQuoteNames = True 81 78 self._keyField = "" 82 79 self._requeryChildOnSave = False … … 110 107 of the cursor. 111 108 """ 112 c n = self._conn109 cf = self._cursorFactory 113 110 cursorClass = self._getCursorClass(self.dCursorMixinClass, 114 111 self.dbapiCursorClass) 115 crs = c n.getCursor(cursorClass)116 crs.BackendObject = c n.getBackendObject()117 crs.setCursorFactory(c n.getCursor, cursorClass)112 crs = cf.getCursor(cursorClass) 113 crs.BackendObject = cf.getBackendObject() 114 crs.setCursorFactory(cf.getCursor, cursorClass) 118 115 return crs 119 116 … … 131 128 if self.__cursors: 132 129 _dataStructure = getattr(self.__cursors[self.__cursors.keys()[0]], "_dataStructure", None) 130 _virtualFields = getattr(self.__cursors[self.__cursors.keys()[0]], "_virtualFields", {}) 133 131 else: 134 132 # The first cursor is being created, before DataStructure is assigned. 135 133 _dataStructure = None 134 _virtualFields = {} 136 135 errMsg = self.beforeCreateCursor() 137 136 if errMsg: … … 144 143 key = self.__currentCursorKey 145 144 146 c n = self._conn147 self.__cursors[key] = c n.getCursor(cursorClass)148 self.__cursors[key].setCursorFactory(c n.getCursor, cursorClass)145 cf = self._cursorFactory 146 self.__cursors[key] = cf.getCursor(cursorClass) 147 self.__cursors[key].setCursorFactory(cf.getCursor, cursorClass) 149 148 150 149 crs = self.__cursors[key] 151 150 if _dataStructure is not None: 152 151 crs._dataStructure = _dataStructure 152 crs._virtualFields = _virtualFields 153 153 crs.KeyField = self.KeyField 154 154 crs.Table = self.DataSource 155 155 crs.AutoPopulatePK = self.AutoPopulatePK 156 crs.BackendObject = cn.getBackendObject() 156 crs.AutoQuoteNames = self.AutoQuoteNames 157 crs.BackendObject = cf.getBackendObject() 157 158 crs.sqlManager = self.SqlManager 158 159 crs.AutoCommit = self.AutoCommit 159 160 crs._bizobj = self 160 crs.setSQL(self.SQL)161 161 if self.RequeryOnLoad: 162 162 crs.requery() … … 270 270 self.save(startTransaction=False, topLevel=False) 271 271 except dException.ConnectionLostException, e: 272 self. _moveToPK(old_pk)272 self.RowNumber = current_row 273 273 raise dException.ConnectionLostException, e 274 274 except dException.DBQueryException, e: … … 277 277 cursor.rollbackTransaction() 278 278 # Pass the exception to the UI 279 self. _moveToPK(old_pk)279 self.RowNumber = current_row 280 280 raise dException.DBQueryException, e 281 281 except dException.dException, e: 282 282 if useTransact: 283 283 cursor.rollbackTransaction() 284 self. _moveToPK(old_pk)284 self.RowNumber = current_row 285 285 raise 286 286 … … 288 288 cursor.commitTransaction() 289 289 290 self.RowNumber = current_row 290 if current_row >= 0: 291 try: 292 self.RowNumber = current_row 293 except: pass 291 294 292 295 … … 388 391 389 392 self.afterCancel() 393 394 395 def deleteAllChildren(self, startTransaction=False): 396 """Delete all children associated with the current record without 397 deleting the current record in this bizobj. 398 """ 399 cursor = self._CurrentCursor 400 errMsg = self.beforeDeleteAllChildren() 401 if errMsg: 402 raise dException.BusinessRuleViolation, errMsg 403 404 if startTransaction: 405 cursor.beginTransaction() 406 407 try: 408 for child in self.__children: 409 child.deleteAll(startTransaction=False) 410 if startTransaction: 411 cursor.commitTransaction() 412 self.afterDeleteAllChildren() 413 414 except dException.DBQueryException, e: 415 if startTransaction: 416 cursor.rollbackTransaction() 417 raise dException.DBQueryException, e 418 except StandardError, e: 419 if startTransaction: 420 cursor.rollbackTransaction() 421 raise StandardError, e 390 422 391 423 … … 439 471 if startTransaction: 440 472 cursor.rollbackTransaction() 441 else: 442 raise dException.DBQueryException, e 473 raise dException.DBQueryException, e 443 474 except StandardError, e: 444 cursor.rollbackTransaction() 475 if startTransaction: 476 cursor.rollbackTransaction() 445 477 raise StandardError, e 446 478 … … 650 682 # sql passed; set it explicitly 651 683 self.SQL = sql 652 # propagate the SQL downward:653 self._CurrentCursor.setSQL(self.SQL)654 684 655 685 … … 716 746 is built. 717 747 """ 718 if self.DataSource and self.LinkField :748 if self.DataSource and self.LinkField and self.Parent: 719 749 if self.Parent.IsAdding: 720 750 # Parent is new and not yet saved, so we cannot have child records yet. … … 759 789 cursor's standard method for merging. 760 790 """ 791 if not isinstance(params, tuple): 792 params = (params, ) 761 793 self.__params = params 762 794 … … 967 999 self.onNew() 968 1000 1001 # Remove the memento for the new record, as we want to only record 1002 # changes made after this point. 1003 cursor._clearMemento() 1004 969 1005 970 1006 def onNew(self): 971 """ Hook method called after the default values have been set in onNew().""" 972 pass 1007 """Called when a new record is added. 1008 1009 Use this hook to add additional default field values, or anything else 1010 you need. If you change field values here, the memento system will not 1011 catch it (the record will not be marked 'dirty'). Use afterNew() if you 1012 instead want the memento system to record the changes. 1013 """ 1014 pass 973 1015 974 1016 … … 1011 1053 1012 1054 1013 def addChildByRelationDict(self, dict, bizModule): 1014 """ Accepts a dictionary containing relationship information 1015 If any of the entries pertain to this bizobj, it will check to make 1016 sure that the child bizobj is already added, or add it and set the 1017 relationship if it isn't. It then passes the dict on to the child to 1018 allow the child to set up its relationships. 1019 1020 Returns a list containing all added child bizobjs. The list will 1021 be empty if none were added. 1022 """ 1055 def _addChildByRelationDict(self, dict, bizModule): 1056 """ Deprecated; used in old datanav framework.""" 1023 1057 addedChildren = [] 1024 1058 if self.__relationDictSet: … … 1056 1090 for candidate, candidateClass in bizModule.__dict__.items(): 1057 1091 if type(candidateClass) == type: 1058 candidateInstance = candidateClass(self._c onn)1092 candidateInstance = candidateClass(self._cursorFactory) 1059 1093 if candidateInstance.DataSource.lower() == target.lower(): 1060 1094 childBizClass = candidateClass 1061 1095 1062 childBiz = childBizClass(self._c onn)1096 childBiz = childBizClass(self._cursorFactory) 1063 1097 self.addChild(childBiz) 1064 1098 addedChildren.append(childBiz) … … 1247 1281 1248 1282 1283 def oldVal(self, fieldName, row=None): 1284 return self._CurrentCursor.oldVal(fieldName, row) 1285 1249 1286 1250 1287 ########## SQL Builder interface section ############## … … 1253 1290 def addFrom(self, exp): 1254 1291 return self._CurrentCursor.addFrom(exp) 1292 def addJoin(self, tbl, exp, joinType=None): 1293 return self._CurrentCursor.addJoin(tbl, exp, joinType) 1255 1294 def addGroupBy(self, exp): 1256 1295 return self._CurrentCursor.addGroupBy(exp) … … 1265 1304 def setFromClause(self, clause): 1266 1305 return self._CurrentCursor.setFromClause(clause) 1306 def setJoinClause(self, clause): 1307 return self._CurrentCursor.setJoinClause(clause) 1267 1308 def setGroupByClause(self, clause): 1268 1309 return self._CurrentCursor.setGroupByClause(clause) 1310 def getLimitClause(self): 1311 return self._CurrentCursor.getLimitClause() 1269 1312 def setLimitClause(self, clause): 1270 1313 return self._CurrentCursor.setLimitClause(clause) 1314 # For simplicity's sake, create aliases 1315 setLimit, getLimit = setLimitClause, getLimitClause 1271 1316 def setOrderByClause(self, clause): 1272 1317 return self._CurrentCursor.setOrderByClause(clause) … … 1275 1320 def prepareWhere(self, clause): 1276 1321 return self._CurrentCursor.prepareWhere(clause) 1277 1322 def getFieldClause(self): 1323 return self._CurrentCursor.getFieldClause() 1324 def getFromClause(self): 1325 return self._CurrentCursor.getFromClause() 1326 def getJoinClause(self): 1327 return self._CurrentCursor.getJoinClause() 1328 def getWhereClause(self): 1329 return self._CurrentCursor.getWhereClause() 1330 def getGroupByClause(self): 1331 return self._CurrentCursor.getGroupByClause() 1332 def getOrderByClause(self): 1333 return self._CurrentCursor.getOrderByClause() 1334 ########## END - SQL Builder interface section ############## 1278 1335 1279 1336 … … 1283 1340 def beforeNew(self): return "" 1284 1341 def beforeDelete(self): return "" 1342 def beforeDeleteAllChildren(self): return "" 1285 1343 def beforeFirst(self): return "" 1286 1344 def beforePrior(self): return "" … … 1295 1353 def beforeCreateCursor(self): return "" 1296 1354 ########## Post-hook interface section ############## 1297 def afterNew(self): pass 1355 def afterNew(self): 1356 """Called after a new record is added. 1357 1358 Use this hook to change field values, or anything else you need. If you 1359 change field values here, the memento system will catch it. If you want 1360 to change field values and not trigger the memento system, use onNew() 1361 instead. 1362 """ 1363 pass 1298 1364 def afterDelete(self): pass 1365 def afterDeleteAllChildren(self): return "" 1299 1366 def afterFirst(self): pass 1300 1367 def afterPrior(self): pass … … 1327 1394 self._autoPopulatePK = bool(val) 1328 1395 if self._CurrentCursor: 1329 self._CurrentCursor.AutoPopulatePK= val 1396 self._CurrentCursor.AutoPopulatePK = val 1397 1398 1399 def _getAutoQuoteNames(self): 1400 return self._autoQuoteNames 1401 1402 def _setAutoQuoteNames(self, val): 1403 self._autoQuoteNames = val 1404 if self._CurrentCursor: 1405 self._CurrentCursor.AutoQuoteNames = val 1330 1406 1331 1407 … … 1402 1478 def _setDefaultValues(self, val): 1403 1479 self._defaultValues = val 1480 1481 1482 def _getVirtualFields(self): 1483 # We need to save the explicitly-assigned VirtualFields here in the bizobj, 1484 # so that we are able to propagate it to any future-assigned child cursors. 1485 _df = getattr(self, "_virtualFields", None) 1486 if _df is not None: 1487 return _df 1488 return self._CurrentCursor.VirtualFields 1489 1490 def _setVirtualFields(self, val): 1491 for key, cursor in self.__cursors.items(): 1492 cursor.VirtualFields = val 1493 self._virtualFields = val 1404 1494 1405 1495 … … 1599 1689 def _setSQL(self, val): 1600 1690 self._SQL = val 1601 cursor = self._CurrentCursor1602 if cursor is not None:1603 cursor.setSQL(val)1604 1691 1605 1692 … … 1608 1695 cursorClass = self._getCursorClass(self.dCursorMixinClass, 1609 1696 self.dbapiCursorClass) 1610 c n = self._conn1611 crs = self._sqlMgrCursor = c n.getCursor(cursorClass)1612 crs.setCursorFactory(c n.getCursor, cursorClass)1697 cf = self._cursorFactory 1698 crs = self._sqlMgrCursor = cf.getCursor(cursorClass) 1699 crs.setCursorFactory(cf.getCursor, cursorClass) 1613 1700 crs.KeyField = self.KeyField 1614 1701 crs.Table = self.DataSource 1615 1702 crs.AutoPopulatePK = self.AutoPopulatePK 1616 crs.BackendObject = cn.getBackendObject() 1703 crs.AutoQuoteNames = self.AutoQuoteNames 1704 crs.BackendObject = cf.getBackendObject() 1617 1705 return self._sqlMgrCursor 1618 1706 … … 1637 1725 _("Determines if we are using a table that auto-generates its PKs. (bool)")) 1638 1726 1727 AutoQuoteNames = property(_getAutoQuoteNames, _setAutoQuoteNames, None, 1728 _("""When True (default), table and column names are enclosed with 1729 quotes during SQL creation in the cursor. (bool)""")) 1730 1639 1731 AutoSQL = property(_getAutoSQL, None, None, 1640 1732 _("Returns the SQL statement automatically generated by the sql manager.")) … … 1678 1770 FillLinkFromParent = property(_getFillLinkFromParent, _setFillLinkFromParent, None, 1679 1771 _("""In the onNew() method, do we fill in the linkField with the value returned 1680 by calling the parent bizobj \'s GetKeyValue() method? (bool)"""))1772 by calling the parent bizobj's GetKeyValue() method? (bool)""")) 1681 1773 1682 1774 IsAdding = property(_isAdding, None, None, … … 1697 1789 1698 1790 NewRecordOnNewParent = property(_getNewRecordOnNewParent, _setNewRecordOnNewParent, None, 1699 _("If this bizobj \'s parent has NewChildOnNew==True, do we create a record here? (bool)"))1791 _("If this bizobj's parent has NewChildOnNew==True, do we create a record here? (bool)")) 1700 1792 1701 1793 NonUpdateFields = property(_getNonUpdateFields, _setNonUpdateFields, None, … … 1740 1832 1741 1833 SQL = property(_getSQL, _setSQL, None, 1742 _("SQL statement used to create the cursor \'s data. (str)"))1834 _("SQL statement used to create the cursor's data. (str)")) 1743 1835 1744 1836 SqlManager = property(_getSqlMgr, None, None, … … 1747 1839 UserSQL = property(_getUserSQL, _setUserSQL, None, 1748 1840 _("SQL statement to run. If set, the automatic SQL builder will not be used.")) 1841 1842 VirtualFields = property(_getVirtualFields, _setVirtualFields, None, 1843 _("""A dictionary mapping virtual_field_name to function to call. 1844 1845 The specified function will be called when getFieldVal() is called on 1846 the specified virtual field name.""")) 1847 branches/carl2/dabo/biz/test/test_dBizobj.py
r2748 r2960 38 38 """ % locals()) 39 39 40 def createNullRecord(self): 41 self.biz._CurrentCursor.AuxCursor.execute(""" 42 insert into %s (cField, iField, nField) values (NULL, NULL, NULL) 43 """ % self.temp_table_name) 40 44 41 45 ## - Begin property unit tests - … … 72 76 or ds[2] == ("iField", "G", False, self.temp_table_name, "iField", None)) 73 77 self.assertEqual(ds[3], ("nField", "N", False, self.temp_table_name, "nField", None)) 78 79 80 def test_DefaultValues(self): 81 biz = self.biz 82 biz.DefaultValues["iField"] = 2342 83 biz.new() 84 self.assertEqual(biz.Record.iField, 2342) 85 self.assertEqual(biz.isChanged(), False) 86 87 def testVirtualFields(self): 88 biz = self.biz 89 def getCombinedName(): 90 return "%s:%s" % (biz.Record.cField.replace(" ", ""), biz.Record.iField) 91 biz.VirtualFields["combined_name"] = getCombinedName 92 93 def testBogus(): 94 return biz.Record.bogus_field_name 95 96 self.assertRaises(dabo.dException.FieldNotFoundException, testBogus) 97 self.assertEqual(biz.Record.combined_name, "PaulKeithMcNett:23") 98 biz.Record.combined_name = "shouldn't be able to set this" 99 self.assertEqual(biz.Record.combined_name, "PaulKeithMcNett:23") 74 100 75 101 def test_Encoding(self): … … 142 168 ## - End property unit tests - 143 169 170 ## - Begin method unit tests - 171 172 def test_cancel(self): 173 biz = self.biz 174 biz.Record.cField = "pkm" 175 biz.cancel() 176 self.assertEqual(biz.Record.cField, "Paul Keith McNett") 177 biz.new() 178 self.assertEqual(biz.RowCount, 4) 179 self.assertEqual(biz.RowNumber, 3) 180 biz.cancel() 181 self.assertEqual(biz.RowCount, 3) 182 self.assertEqual(biz.RowNumber, 2) 183 184 def test_isChanged(self): 185 biz = self.biz 186 self.assertEqual(biz.isChanged(), False) 187 biz.Record.cField = "The Magnificent Seven" 188 self.assertEqual(biz.isChanged(), True) 189 biz.cancel() 190 self.assertEqual(biz.isChanged(), False) 191 192 # isChanged() should be False for new records that haven't had any field 193 # value changes. 194 biz.new() 195 self.assertEqual(biz.isChanged(), False) 196 biz.Record.cField = "Hitsville U.K." 197 self.assertEqual(biz.isChanged(), True) 198 199 200 def test_oldVal(self): 201 biz = self.biz 202 self.assertEqual(biz.oldVal("cField"), biz.Record.cField) 203 self.assertEqual(biz.oldVal("cField", 1), biz.getFieldVal("cField", 1)) 204 oldVal = biz.Record.cField 205 newVal = "pkm23" 206 biz.Record.cField = newVal 207 self.assertEqual(biz.oldVal("cField"), oldVal) 208 self.assertEqual(biz.Record.cField, newVal) 209 self.assertRaises(dabo.dException.FieldNotFoundException, biz.oldVal, "bogusField") 210 211 ## - End method unit tests - 212 213 def testDeleteNewSave(self): 214 biz = self.biz 215 biz.delete() 216 biz.new() 217 biz.save() 218 self.assertEqual(biz.RowCount, 3) 219 self.assertEqual(biz.RowNumber, 2) 220 221 biz.deleteAll() 222 self.assertEqual(biz.RowCount, 0) 223 224 self.assertRaises(dabo.dException.NoRecordsException, biz.save) 225 self.assertRaises(dabo.dException.NoRecordsException, biz.delete) 226 227 biz.new() 228 self.assertEqual(biz.RowCount, 1) 229 biz.delete() 230 self.assertEqual(biz.RowCount, 0) 231 self.assertRaises(dabo.dException.NoRecordsException, biz.save) 232 233 biz.new() 234 biz.save() 235 self.assertEqual(biz.RowCount, 1) 236 self.assertEqual(biz.RowNumber, 0) 237 144 238 145 239 def testMementos(self): … … 175 269 self.assertEqual(biz.RowNumber, 3) 176 270 self.assertEqual(cur._newRecords, {"-1-dabotmp": None}) 177 self.assertEqual(biz.isChanged(), True)271 self.assertEqual(biz.isChanged(), False) ## (because no field changed in new record) 178 272 self.assertEqual(cur.Record.pk, "-1-dabotmp") 179 273 self.assertEqual(biz.Record.cField, "") … … 181 275 self.assertEqual(biz.Record.nField, 0) 182 276 biz.save() 277 self.assertEqual(biz.RowCount, 4) ## still have 4 rows, even though the last one wasn't saved 183 278 biz.requery() 184 self.assertEqual(biz.RowCount, 4) 185 self.assertEqual(biz.RowNumber, 3) 279 # We only have 3 rows, because one of the prior 4 rows was new with no changed fields: 280 self.assertEqual(biz.RowCount, 3) 281 # ...and RowNumber went to 0, because the previous row number (3) doesn't exist anymore: 282 self.assertEqual(biz.RowNumber, 0) 186 283 self.assertEqual(cur._newRecords, {}) 187 284 self.assertEqual(biz.isChanged(), False) 188 self.assertEqual(biz.Record.pk, 4) 189 190 # The new fields should be NULL, since we didn't explicitly set them: 191 self.assertEqual(biz.Record.cField, None) 192 self.assertEqual(biz.Record.iField, None) 193 self.assertEqual(biz.Record.nField, None) 285 self.assertEqual(biz.Record.pk, 1) 286 194 287 195 288 def testChildren(self): … … 206 299 207 300 # At this point bizMain should be at row 0, and bizChild should have 208 # two records, and be on row 0 301 # two records, and be on row 0, and isChanged() should be False, since 302 # no fields have been updated. 209 303 self.assertEqual(bizMain.Record.pk, 1) 210 304 self.assertEqual(bizMain.RowNumber, 0) … … 213 307 self.assertEqual(bizChild.Record.pk, 1) 214 308 self.assertEqual(bizChild.Record.parent_fk, 1) 309 self.assertEqual(bizMain.isChanged(), False) 310 self.assertEqual(bizChild.isChanged(), False) 311 self.assertEqual(bizMain.isAnyChanged(), False) 312 self.assertEqual(bizChild.isAnyChanged(), False) 215 313 216 314 bizMain.next() … … 259 357 self.assertEqual(bizChild.IsAdding, True) 260 358 self.assertEqual(bizChild.RowCount, 1) 359 self.assertEqual(bizChild.isAnyChanged(), False) 360 self.assertEqual(bizChild.isChanged(), False) 361 self.assertEqual(bizMain.isAnyChanged(), False) 362 self.assertEqual(bizMain.isChanged(), False) 363 bizChild.Record.cInvNum = "IN99991" 364 self.assertEqual(bizMain.isChanged(), True) 365 self.assertEqual(bizMain.isAnyChanged(), True) 366 self.assertEqual(bizChild.isChanged(), True) 261 367 self.assertEqual(bizChild.isAnyChanged(), True) 262 self.assertEqual(bizChild.isChanged(), True)263 self.assertEqual(bizMain.isAnyChanged(), True)264 self.assertEqual(bizMain.isChanged(), True)265 bizChild.Record.cInvNum = "IN99991"266 368 267 369 bizMain.prior() … … 296 398 # Test the case where you add a new parent record but no new children: 297 399 bizMain.new() 400 bizMain.Record.cField = "Junco Pardner" 298 401 self.assertEqual(bizMain.RowCount, 4) 299 402 self.assertEqual(bizMain.RowNumber, 3) … … 305 408 self.assertEqual(bizMain.RowNumber, 3) 306 409 410 def testNullRecord(self): 411 biz = self.biz 412 self.createNullRecord() 413
