Changeset 3044

Show
Ignore:
Timestamp:
04/10/2007 09:17:53 AM (2 years ago)
Author:
ed
Message:

Changed the logic surrounding field-level validation to distinguish when a rule has passed versus the case where there is simply no rule. This is implemented with the new BusinessRulePassed? exception class, which is caught by dForm, and then calls onFieldValidationPassed(). By default, this method will clear the status text set by a prior onFieldValidationFailed() call.

Also updated the data controls to validate changes if the user changes the field value back to its original value, so that we can determine that the 'new' value will also pass validation, and clear the StatusText?.

Changed the alias used for dConstants from 'k' to 'kons', as I feel it is more readable.

Files:

Legend:

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

    r3038 r3044  
    22import re 
    33import dabo 
    4 import dabo.dConstants as k 
     4import dabo.dConstants as kons 
    55from dabo.db.dCursorMixin import dCursorMixin 
    66from dabo.dLocalize import _ 
     
    8989        ### RESTRICT - don't allow action if there are child records 
    9090        ### CASCADE - changes to the parent are cascaded to the children 
    91         self.deleteChildLogic = k.REFINTEG_CASCADE  # child records will be deleted 
    92         self.updateChildLogic = k.REFINTEG_IGNORE   # parent keys can be changed w/o 
     91        self.deleteChildLogic = kons.REFINTEG_CASCADE  # child records will be deleted 
     92        self.updateChildLogic = kons.REFINTEG_IGNORE   # parent keys can be changed w/o 
    9393                                                    # affecting children 
    94         self.insertChildLogic = k.REFINTEG_IGNORE   # child records can be inserted 
     94        self.insertChildLogic = kons.REFINTEG_IGNORE   # child records can be inserted 
    9595                                                    # even if no parent record exists. 
    9696        ########################################## 
     
    436436            raise dException.dException, _("No key field defined for table: ") + self.DataSource 
    437437 
    438         if self.deleteChildLogic == k.REFINTEG_RESTRICT: 
     438        if self.deleteChildLogic == kons.REFINTEG_RESTRICT: 
    439439            # See if there are any child records 
    440440            for child in self.__children: 
     
    454454            # populate them with data for the current record in this bizobj. 
    455455            for child in self.__children: 
    456                 if self.deleteChildLogic == k.REFINTEG_CASCADE: 
     456                if self.deleteChildLogic == kons.REFINTEG_CASCADE: 
    457457                    child.deleteAll(startTransaction=False) 
    458458                else: 
     
    852852        errMsg = "" 
    853853        message = self.validateField(fld, val) 
     854        if message == kons.BIZ_DEFAULT_FIELD_VALID: 
     855            # No validation was done 
     856            print "DEFAULT VALID" 
     857            return 
    854858        if message: 
    855859            errMsg += message 
    856860        if errMsg: 
    857861            raise dException.BusinessRuleViolation, errMsg 
     862        else: 
     863            print "BIZ RULE PASSED" 
     864            raise dException.BusinessRulePassed 
    858865 
    859866 
     
    866873        from being changed. 
    867874        """ 
    868         pass 
     875        return kons.BIZ_DEFAULT_FIELD_VALID 
    869876 
    870877 
  • trunk/dabo/dConstants.py

    r1591 r3044  
    2828DLG_OK = 0 
    2929DLG_CANCEL = -1 
     30 
     31# Flag to indicate that field validation was skipped 
     32BIZ_DEFAULT_FIELD_VALID = "Dabo default field validation".split(" ") 
  • trunk/dabo/dException.py

    r2994 r3044  
    2020 
    2121class BusinessRuleViolation(dException): 
     22    pass 
     23     
     24class BusinessRulePassed(dException): 
    2225    pass 
    2326     
  • trunk/dabo/db/dCursorMixin.py

    r3042 r3044  
    628628            recKey = self.pkExpression(rec) 
    629629            memento = self._mementos.get(recKey, None) 
    630              
    631630            return bool(memento) 
    632631 
  • trunk/dabo/ui/dDataControlMixinBase.py

    r3021 r3044  
    5555        if not self._inFldValid: 
    5656            self._oldVal = self.Value 
    57         self._inFldValid = False 
    5857        try: 
    5958            if self.SelectOnEntry: 
     
    6665    def _lostFocus(self): 
    6766        ok = True 
    68         if self._oldVal != self.Value
     67        if self._inFldValid or (self._oldVal != self.Value)
    6968            # Call the field-level validation if indicated. 
    7069            if hasattr(self.Form, "validateField"): 
     
    7877            # Everything's hunky dory; push the value to the DataSource. 
    7978            self.flushValue() 
     79            self._inFldValid = False 
    8080        try: 
    8181            if self.SelectOnEntry: 
  • trunk/dabo/ui/uiwx/dForm.py

    r3039 r3044  
    708708        except dException.BusinessRuleViolation, e: 
    709709            self.onFieldValidationFailed(ctrl, ds, df, val, e) 
     710        except dException.BusinessRulePassed: 
     711            self.onFieldValidationPassed(ctrl, ds, df, val) 
     712            ret = True 
    710713        return ret 
    711714 
     
    716719        appropriately for your application. 
    717720        """ 
    718         self.setStatusText(_("Validation failed for %s: %s") % (df, err)
     721        self.StatusText = _("Validation failed for %s: %s") % (df, err
    719722        dabo.ui.callAfter(ctrl.setFocus) 
     723         
     724     
     725    def onFieldValidationPassed(self, ctrl, ds, df, val): 
     726        """Basic handling when field-level validation succeeds.  
     727        You should override it with your own code to handle this event  
     728        appropriately for your application. 
     729        """ 
     730        self.StatusText = "" 
    720731         
    721732