def state_active_valid(self, intervention, user=None): self.check_required_fields(intervention) self.check_rigid_fields(intervention, related=True) today = date.today() if not (intervention.start <= today): raise StateValidError([_('Today is not after the start date')]) if intervention.total_unicef_budget == 0: raise StateValidError([_('UNICEF Cash $ or UNICEF Supplies $ should not be 0')]) return True
def state_ended_valid(self, intervention, user=None): self.check_required_fields(intervention) self.check_rigid_fields(intervention, related=True) today = date.today() if not today > intervention.end: raise StateValidError([_('Today is not after the end date')]) return True
def check_rigid_fields(self, intervention, related=False): # this can be set if running in a task and old_instance is not set if self.disable_rigid_check: return rigid_fields = [f for f in self.permissions['edit'] if self.permissions['edit'][f] is False] rigid_valid, field = check_rigid_fields(intervention, rigid_fields, related=related) if not rigid_valid: raise StateValidError(['Cannot change fields while in {}: {}'.format(intervention.status, field)])
def state_ended_valid(self, agreement, user=None): # for SSFAs there will be no states valid since the states are forced by the Interventions # Once signed, nothing will be editable on the agreement level if agreement.agreement_type == agreement.SSFA: return False self.check_required_fields(agreement) self.check_rigid_fields(agreement, related=True) today = date.today() if not today > agreement.end: raise StateValidError([_('Today is not after the end date')]) return True
def check_required_fields(self, intervention): required_fields = [ f for f in self.permissions['required'] if self.permissions['required'][f] is True ] required_valid, field = check_required_fields(intervention, required_fields) if not required_valid: raise StateValidError([ 'Required fields not completed in {}: {}'.format( intervention.status, field) ])
def test_state_valid_error(self): '''Ensure StateValidError inherits from _BaseStateError''' self.assertIsInstance(StateValidError(), _BaseStateError)
def state_signed_valid(self, intervention, user=None): self.check_required_fields(intervention) self.check_rigid_fields(intervention, related=True) if intervention.total_unicef_budget == 0: raise StateValidError([_('UNICEF Cash $ or UNICEF Supplies $ should not be 0')]) return True