Changeset 1911
- Timestamp:
- 02/08/2006 02:39:33 PM (3 years ago)
- Files:
-
- trunk/dabo/biz/dBizobj.py (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/biz/dBizobj.py
r1910 r1911 10 10 11 11 class dBizobj(dObject): 12 """ The middle tier, where the business logic resides. 13 """ 12 """ The middle tier, where the business logic resides.""" 14 13 # Class to instantiate for the cursor object 15 14 dCursorMixinClass = dCursorMixin 16 17 15 # Need to set this here 18 16 useFieldProps = False 19 20 17 # Tell dObject that we'll call before and afterInit manually: 21 18 _call_beforeInit, _call_afterInit, _call_initProperties = False, False, False 19 22 20 23 21 def __init__(self, conn, properties=None, *args, **kwargs): … … 25 23 self._beforeInit() 26 24 self._conn = conn 25 # Do we use autocommit for transactions? 26 self._autoCommit = False 27 27 28 28 super(dBizobj, self).__init__(properties=properties, *args, **kwargs) … … 121 121 err = True 122 122 if err: 123 raise AttributeError, " '%s' object has no attribute '%s' "% (self.__class__.__name__, att)123 raise AttributeError, _(" '%s' object has no attribute '%s' ") % (self.__class__.__name__, att) 124 124 return ret 125 125 … … 172 172 crs.BackendObject = cn.getBackendObject() 173 173 crs.sqlManager = self.SqlManager 174 crs.AutoCommit = self.AutoCommit 174 175 crs.setSQL(self.SQL) 175 176 if self.RequeryOnLoad: … … 274 275 useTransact = startTransaction or topLevel 275 276 if useTransact: 276 # Tell the cursor to issue a BEGIN TRANSACTION command277 # Tell the cursor to begin a transaction, if needed. 277 278 cursor.beginTransaction() 278 279 … … 306 307 called as well. 307 308 """ 309 310 dabo.trace() 311 312 308 313 cursor = self._CurrentCursor 309 314 errMsg = self.beforeSave() … … 312 317 313 318 if self.KeyField is None: 314 raise dException.dException, "No key field defined for table: "+ self.DataSource319 raise dException.dException, _("No key field defined for table: ") + self.DataSource 315 320 316 321 # Validate any changes to the data. If there is data that fails … … 320 325 useTransact = startTransaction or topLevel 321 326 if useTransact: 322 # Tell the cursor to issue a BEGIN TRANSACTION command327 # Tell the cursor to begin a transaction, if needed. 323 328 cursor.beginTransaction() 324 329 … … 395 400 396 401 def delete(self, startTransaction=False): 397 """ Delete the current row of the data set. 398 """ 402 """ Delete the current row of the data set.""" 399 403 cursor = self._CurrentCursor 400 404 errMsg = self.beforeDelete() … … 405 409 406 410 if self.KeyField is None: 407 raise dException.dException, "No key field defined for table: "+ self.DataSource411 raise dException.dException, _("No key field defined for table: ") + self.DataSource 408 412 409 413 if self.deleteChildLogic == k.REFINTEG_RESTRICT: … … 443 447 444 448 def deleteAll(self, startTransaction=False): 445 """ Delete all rows in the data set. 446 """ 449 """ Delete all rows in the data set.""" 447 450 while self.RowCount > 0: 448 451 self.first() … … 599 602 raise dException.dException, errMsg 600 603 if self.KeyField is None: 601 errMsg = "No Primary Key defined in the Bizobj for " +self.DataSource604 errMsg = _("No Primary Key defined in the Bizobj for %s") % self.DataSource 602 605 raise dException.MissingPKException, errMsg 603 606 … … 835 838 836 839 def onDeleteLastRecord(self): 837 """ Hook called when the last record has been deleted from the data set. 838 """ 840 """ Hook called when the last record has been deleted from the data set.""" 839 841 pass 840 842 841 843 842 844 def _onSaveNew(self): 843 """ Called after successfully saving a new record. 844 """ 845 """ Called after successfully saving a new record.""" 845 846 # If this is a new parent record with a new auto-generated PK, pass it on 846 847 # to the children before they save themselves. … … 854 855 855 856 def onSaveNew(self): 856 """ Hook method called after successfully saving a new record. 857 """ 857 """ Hook method called after successfully saving a new record.""" 858 858 pass 859 859 … … 866 866 cursor = self._CurrentCursor 867 867 cursor.setDefaults(self.DefaultValues) 868 869 868 if self.AutoPopulatePK: 870 869 # Provide a temporary PK so that any linked children can be properly 871 870 # identified until the record is saved and a permanent PK is obtained. 872 871 cursor.genTempAutoPK() 873 874 872 # Fill in the link to the parent record 875 873 if self.Parent and self.FillLinkFromParent and self.LinkField: 876 874 self.setParentFK() 877 878 875 # Call the custom hook method 879 876 self.onNew() … … 881 878 882 879 def onNew(self): 883 """ Hook method called after the default values have been set in onNew(). 884 """ 880 """ Hook method called after the default values have been set in onNew().""" 885 881 pass 886 882 … … 1023 1019 1024 1020 def getPK(self): 1025 """ Return the value of the PK field. 1026 """ 1021 """ Return the value of the PK field.""" 1027 1022 if self.KeyField is None: 1028 raise dException.dException, "No key field defined for table: " + self.DataSource 1029 1023 raise dException.dException, _("No key field defined for table: ") + self.DataSource 1030 1024 return self._CurrentCursor.getFieldVal(self.KeyField) 1031 1025 … … 1044 1038 1045 1039 def getFieldVal(self, fld, row=None): 1046 """ Return the value of the specified field in the current or specified row. 1047 """ 1040 """ Return the value of the specified field in the current or specified row.""" 1048 1041 cursor = self._CurrentCursor 1049 1042 if cursor is not None: … … 1054 1047 1055 1048 def setFieldVal(self, fld, val): 1056 """ Set the value of the specified field in the current row. 1057 """ 1049 """ Set the value of the specified field in the current row.""" 1058 1050 cursor = self._CurrentCursor 1059 1051 if cursor is not None: … … 1129 1121 1130 1122 def getChildren(self): 1131 """ Return a tuple of the child bizobjs. 1132 """ 1123 """ Return a tuple of the child bizobjs.""" 1133 1124 ret = [] 1134 1125 for child in self.__children: … … 1138 1129 1139 1130 def getChildByDataSource(self, dataSource): 1140 """ Return a reference to the child bizobj with the passed dataSource. 1141 """ 1131 """ Return a reference to the child bizobj with the passed dataSource.""" 1142 1132 ret = None 1143 1133 for child in self.getChildren(): … … 1170 1160 1171 1161 1172 def _getNonUpdateFields(self):1173 return self._CurrentCursor.getNonUpdateFields()1174 1175 def _setNonUpdateFields(self, fldList=None):1176 if fldList is None:1177 fldList = []1178 self._CurrentCursor.setNonUpdateFields(fldList)1179 1180 1162 def getWordMatchFormat(self): 1181 1163 return self._CurrentCursor.getWordMatchFormat() … … 1246 1228 1247 1229 1230 def _getAutoCommit(self): 1231 return self._CurrentCursor.AutoCommit 1232 1233 def _setAutoCommit(self, val): 1234 self._CurrentCursor.AutoCommit = val 1235 1236 1237 def _getAutoPopulatePK(self): 1238 try: 1239 return self._autoPopulatePK 1240 except AttributeError: 1241 return True 1242 1243 def _setAutoPopulatePK(self, val): 1244 self._autoPopulatePK = bool(val) 1245 1246 1248 1247 def _getAutoSQL(self): 1249 1248 try: … … 1321 1320 1322 1321 1323 def _get RequeryOnLoad(self):1324 try: 1325 ret = self._requeryOnLoad1322 def _getFillLinkFromParent(self): 1323 try: 1324 return self._fillLinkFromParent 1326 1325 except AttributeError: 1327 ret = False 1328 return ret 1329 1330 def _setRequeryOnLoad(self, val): 1331 self._requeryOnLoad = bool(val) 1332 1333 1334 def _getParent(self): 1335 try: 1336 return self._parent 1337 except AttributeError: 1338 return None 1339 1340 def _setParent(self, val): 1341 if isinstance(val, dBizobj): 1342 self._parent = val 1343 else: 1344 raise TypeError, "Parent must descend from dBizobj" 1345 1346 1347 def _getAutoPopulatePK(self): 1348 try: 1349 return self._autoPopulatePK 1350 except AttributeError: 1351 return True 1352 1353 def _setAutoPopulatePK(self, val): 1354 self._autoPopulatePK = bool(val) 1355 1356 1326 return False 1327 1328 def _setFillLinkFromParent(self, val): 1329 self._fillLinkFromParent = bool(val) 1330 1331 1332 def _isAdding(self): 1333 return self._CurrentCursor.IsAdding 1334 1335 1357 1336 def _getKeyField(self): 1358 1337 try: … … 1368 1347 1369 1348 1370 def _getLinkField(self):1371 try:1372 return self._linkField1373 except AttributeError:1374 return ""1375 1376 def _setLinkField(self, val):1377 self._linkField = str(val)1378 1379 1380 def _getParentLinkField(self):1381 try:1382 return self._parentLinkField1383 except AttributeError:1384 return ""1385 1386 def _setParentLinkField(self, val):1387 self._parentLinkField = str(val)1388 1389 1390 def _getRequeryChildOnSave(self):1391 try:1392 return self._requeryChildOnSave1393 except AttributeError:1394 return False1395 1396 def _setRequeryChildOnSave(self, val):1397 self._requeryChildOnSave = bool(val)1398 1399 1400 def _getNewRecordOnNewParent(self):1401 try:1402 return self._newRecordOnNewParent1403 except AttributeError:1404 return False1405 1406 def _setNewRecordOnNewParent(self, val):1407 self._newRecordOnNewParent = bool(val)1408 1409 1410 def _getNewChildOnNew(self):1411 try:1412 return self._newChildOnNew1413 except AttributeError:1414 return False1415 1416 def _setNewChildOnNew(self, val):1417 self._newChildOnNew = bool(val)1418 1419 1420 def _getFillLinkFromParent(self):1421 try:1422 return self._fillLinkFromParent1423 except AttributeError:1424 return False1425 1426 def _setFillLinkFromParent(self, val):1427 self._fillLinkFromParent = bool(val)1428 1429 1430 def _isAdding(self):1431 return self._CurrentCursor.IsAdding1432 1433 1434 1349 def _getLastSQL(self): 1435 1350 try: … … 1440 1355 1441 1356 1357 def _getLinkField(self): 1358 try: 1359 return self._linkField 1360 except AttributeError: 1361 return "" 1362 1363 def _setLinkField(self, val): 1364 self._linkField = str(val) 1365 1366 1367 def _getNewChildOnNew(self): 1368 try: 1369 return self._newChildOnNew 1370 except AttributeError: 1371 return False 1372 1373 def _setNewChildOnNew(self, val): 1374 self._newChildOnNew = bool(val) 1375 1376 1377 def _getNewRecordOnNewParent(self): 1378 try: 1379 return self._newRecordOnNewParent 1380 except AttributeError: 1381 return False 1382 1383 def _setNewRecordOnNewParent(self, val): 1384 self._newRecordOnNewParent = bool(val) 1385 1386 1387 def _getNonUpdateFields(self): 1388 return self._CurrentCursor.getNonUpdateFields() 1389 1390 def _setNonUpdateFields(self, fldList=None): 1391 if fldList is None: 1392 fldList = [] 1393 self._CurrentCursor.setNonUpdateFields(fldList) 1394 1395 1396 def _getParent(self): 1397 try: 1398 return self._parent 1399 except AttributeError: 1400 return None 1401 1402 def _setParent(self, val): 1403 if isinstance(val, dBizobj): 1404 self._parent = val 1405 else: 1406 raise TypeError, _("Parent must descend from dBizobj") 1407 1408 1409 def _getParentLinkField(self): 1410 try: 1411 return self._parentLinkField 1412 except AttributeError: 1413 return "" 1414 1415 def _setParentLinkField(self, val): 1416 self._parentLinkField = str(val) 1417 1418 1419 def _getRequeryChildOnSave(self): 1420 try: 1421 return self._requeryChildOnSave 1422 except AttributeError: 1423 return False 1424 1425 def _setRequeryChildOnSave(self, val): 1426 self._requeryChildOnSave = bool(val) 1427 1428 1429 def _getRequeryOnLoad(self): 1430 try: 1431 ret = self._requeryOnLoad 1432 except AttributeError: 1433 ret = False 1434 return ret 1435 1436 def _setRequeryOnLoad(self, val): 1437 self._requeryOnLoad = bool(val) 1438 1439 1442 1440 def _getRestorePositionOnRequery(self): 1443 1441 try: … … 1517 1515 1518 1516 ### -------------- Property Definitions ------------------ ## 1517 AutoCommit = property(_getAutoCommit, _setAutoCommit, None, 1518 _("Do we need explicit begin/commit/rollback commands for transactions? (bool)")) 1519 1519 1520 1520 AutoPopulatePK = property(_getAutoPopulatePK, _setAutoPopulatePK, None,
