Changeset 4057
- Timestamp:
- 05/02/08 07:21:25 (3 months ago)
- Files:
-
- trunk/dabo/biz/dBizobj.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/biz/dBizobj.py
r4055 r4057 848 848 """ 849 849 if self.DataSource and self.LinkField and self.Parent: 850 if self.Parent. IsAdding or self.Parent.RowCount == 0:850 if self.Parent.RowCount == 0: 851 851 # Parent is new and not yet saved, so we cannot have child records yet. 852 852 self.setWhereClause("") 853 853 filtExpr = " 1 = 0 " 854 854 else: 855 if self.ParentLinkField: 856 # The link to the parent is something other than the PK 857 val = self.escQuote(self.Parent.getFieldVal(self.ParentLinkField)) 858 else: 859 val = self.escQuote(self.getParentPK()) 855 val = self.escQuote(self.getParentLinkValue()) 860 856 linkFieldParts = self.LinkField.split(".") 861 857 if len(linkFieldParts) < 2: … … 868 864 filtExpr = " %s.%s = %s " % (dataSource, linkField, val) 869 865 self._CurrentCursor.setChildFilterClause(filtExpr) 866 867 868 def getParentLinkValue(self): 869 """Return the value of the parent record on which this bizobj is dependent. Usually this 870 is the PK of the parent, but can be a non-PK field, if this bizobj's ParentLinkField is 871 not empty. 872 """ 873 ret = None 874 if self.Parent: 875 fld = self.ParentLinkField 876 if not fld: 877 fld = self.Parent.KeyField 878 try: 879 ret = self.Parent.getFieldVal(fld) 880 except dException.NoRecordsException: 881 ret = NO_RECORDS_PK 882 return ret 870 883 871 884 … … 971 984 self._CurrentCursor.moveToRowNum(rownum) 972 985 if updateChildren: 973 pk = self.getPK()974 986 for child in self.__children: 975 # Let the child know the current dependent PK976 child.setCurrentParent( pk)987 # Let the child update to the current record. 988 child.setCurrentParent() 977 989 978 990 … … 986 998 if updateChildren: 987 999 for child in self.__children: 988 # Let the child know the current dependent PK989 child.setCurrentParent( pk)1000 # Let the child update to the current record. 1001 child.setCurrentParent() 990 1002 991 1003 … … 1022 1034 1023 1035 1024 def isAnyChanged(self, parentPK=None):1036 def isAnyChanged(self, useCurrentParent=None): 1025 1037 """Returns True if any record in the current record set has been changed.""" 1026 if parentPKis None:1038 if useCurrentParent is None: 1027 1039 try: 1028 1040 cc = self._CurrentCursor … … 1030 1042 cc = None 1031 1043 else: 1032 cc = self.__cursors.get(parentPK, None) 1044 key = self.getParentLinkValue() 1045 cc = self.__cursors.get(key, None) 1033 1046 if cc is None: 1034 1047 # No cursor, no changes. … … 1039 1052 1040 1053 # Nothing's changed in the top level, so we need to recurse the children: 1041 try:1042 pk = self.getPK()1043 except dException.NoRecordsException:1044 # If there are no records, there can be no changes1045 return False1046 1047 1054 for child in self.__children: 1048 if child.isAnyChanged( parentPK=pk):1055 if child.isAnyChanged(useCurrentParent=useCurrentParent): 1049 1056 return True 1050 1057 # If we made it to here, there are no changes. … … 1069 1076 if not ret: 1070 1077 # see if any child bizobjs have changed 1071 try: 1072 pk = self.getPK() 1073 except dException.NoRecordsException: 1078 if not self.RowCount: 1074 1079 # If there are no records, there can be no changes 1075 1080 return False 1076 1081 for child in self.__children: 1077 ret = child.isAnyChanged( parentPK=pk)1082 ret = child.isAnyChanged(useCurrentParent=True) 1078 1083 if ret: 1079 1084 break … … 1149 1154 if self.LinkField: 1150 1155 if val is None: 1151 val = self.getParent PK()1156 val = self.getParentLinkValue() 1152 1157 self.scan(self._setParentFK, val) 1153 1158 … … 1156 1161 1157 1162 1158 def setCurrentParent(self, val=None , fromChildRequery=None):1159 """ Lets dependent child bizobjs know the current value of theirparent1163 def setCurrentParent(self, val=None): 1164 """ Lets dependent child bizobjs update to the current parent 1160 1165 record. 1161 1166 """ 1162 1167 if self.LinkField: 1163 if val is None and not fromChildRequery:1164 val = self.getParent PK()1168 if val is None: 1169 val = self.getParentLinkValue() 1165 1170 # Update the key value for the cursor 1166 1171 self.__currentCursorKey = val … … 1264 1269 raise dException.BusinessRuleViolation, errMsg 1265 1270 1266 newAutopop = (self.IsAdding and self.AutoPopulatePK)1267 try:1268 pk = self.getPK()1269 except dException.NoRecordsException:1270 # There aren't any records, all children should requery to 0 records.1271 # We can't set the pk to None, because None has special meaning1272 # elsewhere (self.__currentCursorKey).1273 pk = NO_RECORDS_PK1274 1275 1271 for child in self.__children: 1276 1272 # Let the child know the current dependent PK 1277 1273 if child.RequeryWithParent: 1278 child.setCurrentParent(pk, fromChildRequery=True) 1279 if newAutopop and (child.RowCount == 0): 1280 parentPK = None 1281 else: 1282 parentPK = pk 1283 if not child.isAnyChanged(parentPK=parentPK): 1274 child.setCurrentParent() 1275 if not child.isAnyChanged(useCurrentParent=True): 1284 1276 child.requery() 1285 1277 self.afterChildRequery()
