Changeset 3038

Show
Ignore:
Timestamp:
04/06/07 09:21:50 (2 years ago)
Author:
ed
Message:

Fixed a problem where canceling a bizobj that had no records caused an exception that was being displayed with notifyUser(). Normally, a bizobj with no records does not need canceling, so raising such an error is not appropriate. You can still have the old behavior by calling cancel() with 'ignoreNoRecords = False'.

Added some performance enhancements to dForm. Now calling refresh() or update() repeatedly in a loop will only result in one call getting executed. Added several refresh() calls to methods whose results could result in controls not reflecting those changes.

Fixed a bug reported by Larry Long and John Fabiani that involved requerying one bizobj resulted in checking for pending changes in other bizobjs that were not involved in the requery.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/biz/dBizobj.py

    r3029 r3038  
    367367 
    368368 
    369     def cancelAll(self): 
     369    def cancelAll(self, ignoreNoRecords=None): 
    370370        """Cancel all changes made to the current dataset, including all children.""" 
    371         self.scanChangedRows(self.cancel, allCursors=False
    372  
    373  
    374     def cancel(self): 
     371        self.scanChangedRows(self.cancel, allCursors=False, ignoreNoRecords=ignoreNoRecords
     372 
     373 
     374    def cancel(self, ignoreNoRecords=None): 
    375375        """Cancel all changes to the current record and all children. 
    376376 
     
    382382        if errMsg: 
    383383            raise dException.BusinessRuleViolation, errMsg 
     384        if ignoreNoRecords is None: 
     385            # Canceling changes when there are no records should  
     386            # normally not be a problem. 
     387            ignoreNoRecords = True 
    384388 
    385389        # Tell the cursor and all children to cancel themselves: 
    386         self._CurrentCursor.cancel(
     390        self._CurrentCursor.cancel(ignoreNoRecords=ignoreNoRecords
    387391        for child in self.__children: 
    388             child.cancelAll(
     392            child.cancelAll(ignoreNoRecords=ignoreNoRecords
    389393 
    390394        self.afterCancel() 
  • trunk/dabo/db/dCursorMixin.py

    r3025 r3038  
    630630            #new_rec = self._newRecords.has_key(recKey) 
    631631            #return not (memento is None and not new_rec) 
    632             return not (not memento) 
     632            return bool(memento) 
    633633 
    634634 
     
    12011201 
    12021202 
    1203     def cancel(self, allRows=False): 
     1203    def cancel(self, allRows=False, ignoreNoRecords=None): 
    12041204        """ Revert any changes to the data set back to the original values.""" 
    1205         if not self.RowCount > 0: 
    1206             raise dException.NoRecordsException, _("No data to cancel.") 
    1207  
     1205        if ignoreNoRecords is None: 
     1206            ignoreNoRecords = True 
     1207        if self.RowCount == 0: 
     1208            if ignoreNoRecords: 
     1209                # Nothing to do! 
     1210                return 
     1211            else: 
     1212                raise dException.NoRecordsException, _("No data to cancel.") 
     1213         
    12081214        # Faster to deal with 2 specific cases: all rows or just current row 
    12091215        if allRows: 
  • trunk/dabo/ui/uiwx/dForm.py

    r3033 r3038  
    9696 
    9797 
    98     def confirmChanges(self): 
     98    def refresh(self): 
     99        """For performance reasons, cache repeated calls.""" 
     100        dabo.ui.callAfterInterval(100, self.__refresh) 
     101    def __refresh(self): 
     102        super(BaseForm, self).refresh() 
     103         
     104         
     105    def update(self): 
     106        """For performance reasons, cache repeated calls.""" 
     107        dabo.ui.callAfterInterval(100, self.__update) 
     108    def __update(self): 
     109        super(BaseForm, self).update() 
     110         
     111         
     112    def confirmChanges(self, bizobjs=None): 
    99113        """Ask the user if they want to save changes, discard changes, or cancel. 
    100114 
    101115        The user will be queried if the form's CheckForChanges property is True, and 
    102         if there are any pending changes on the form's bizobjs as specified in the 
    103         return value of getBizobjsToCheck(). 
     116        if there are any pending changes on the form's bizobjs as specified in either 
     117        the 'bizobjs' parameter, or, if no parameter is sent, the return value of  
     118        getBizobjsToCheck(). 
    104119 
    105120        If all the above are True, the dialog will be presented. "Yes" will cause 
     
    114129            # Don't bother checking 
    115130            return True 
    116         bizList = self.getBizobjsToCheck() 
     131        if bizobjs is None: 
     132            bizobjs = self.getBizobjsToCheck() 
     133        if not isinstance(bizobjs, (list, tuple)): 
     134            bizList = (bizobjs, ) 
     135        else: 
     136            bizList = bizobjs 
    117137        changedBizList = [] 
    118138         
     
    124144            queryMessage = self.getConfirmChangesQueryMessage(changedBizList) 
    125145            response = dabo.ui.areYouSure(queryMessage, parent=self) 
     146             
     147            print "RESP", response 
    126148            if response == None:     ## cancel 
    127149                # Don't let the form close, or requery happen 
     
    132154            elif response == False:  ## no 
    133155                for biz in changedBizList: 
    134                     self.cancel(dataSource=biz.DataSource) 
     156                    if biz.RowCount: 
     157                        self.cancel(dataSource=biz.DataSource) 
    135158        return True 
    136159     
     
    155178        required bizobjs. 
    156179        """ 
    157         return [self.PrimaryBizobj] 
     180        return (self.PrimaryBizobj, ) 
    158181         
    159182         
     
    215238            self.update() 
    216239        self.afterPointerMove() 
     240        self.refresh() 
    217241        return True 
    218242 
     
    315339 
    316340        self.afterSave() 
     341        self.refresh() 
    317342        return True 
    318343     
    319344     
    320     def cancel(self, dataSource=None): 
     345    def cancel(self, dataSource=None, ignoreNoRecords=None): 
    321346        """ Ask the bizobj to cancel its changes. 
    322347 
     
    329354            return 
    330355        self.activeControlValid() 
     356        if ignoreNoRecords is None: 
     357            ignoreNoRecords = True 
    331358 
    332359        err = self.beforeCancel() 
     
    336363        try: 
    337364            if self.SaveAllRows: 
    338                 bizobj.cancelAll(
     365                bizobj.cancelAll(ignoreNoRecords=ignoreNoRecords
    339366            else: 
    340                 bizobj.cancel(
     367                bizobj.cancel(ignoreNoRecords=ignoreNoRecords
    341368            self.setStatusText(_("Changes to %s canceled.") % ( 
    342369                    self.SaveAllRows and "all records" or "current record",)) 
    343370            self.update() 
     371        except dException.NoRecordsException, e: 
     372            dabo.errorLog.write(_("Cancel failed; no records to cancel.")) 
    344373        except dException.dException, e: 
    345374            dabo.errorLog.write(_("Cancel failed with response: %s") % str(e)) 
    346375            self.notifyUser(str(e), title=_("Cancel Not Allowed") ) 
    347376        self.afterCancel() 
     377        self.refresh() 
    348378 
    349379 
     
    368398            self.notifyUser(err) 
    369399            return 
    370          
    371         if not self.confirmChanges(): 
     400        if not self.confirmChanges(bizobjs=bizobj): 
    372401            # A False from confirmChanges means "don't proceed" 
    373402            return 
    374403 
    375 #       self.setStatusText(_("Please wait... requerying dataset...")) 
    376          
    377404        try: 
    378405            busy = dabo.ui.busyInfo(_("Please wait... requerying dataset...")) 
     
    388415            # Notify listeners that the row number changed: 
    389416            self.raiseEvent(dEvents.RowNumChanged) 
    390              
    391417            # We made it through without errors 
    392418            ret = True 
     
    420446 
    421447        self.afterRequery() 
     448        self.refresh() 
    422449        return ret 
    423450         
     
    464491            self.afterDelete() 
    465492        self.update() 
    466          
     493        self.refresh() 
     494 
    467495 
    468496    def deleteAll(self, dataSource=None, message=None): 
     
    496524        self.afterDeleteAll() 
    497525        self.update() 
     526        self.refresh() 
    498527         
    499528 
     
    525554        self.afterNew() 
    526555        self.update() 
     556        self.refresh() 
    527557         
    528558