def validate_invariants(self): '''Return <errors>''' errors = [] obj = self.obj schema = obj.get_schema() # Descend into field invariants recurse = False try: recurse = schema.getTaggedValue('recurse-on-invariants') except KeyError: pass if recurse: for k, field in obj.iter_fields(): f = field.get(obj) ef = self._validate_invariants_for_field(f, field) if ef: errors.append((k, ef)) # Check own invariants try: ef = [] schema.validateInvariants(obj, ef) except zope.interface.Invalid: errors.append((None, ef)) return errors
def checkInvariants(form_fields, form_data, context): """See `zope.formlib.interfaces.IFormAPI.checkInvariants`""" # First, collect the data for the various schemas schema_data = {} for form_field in form_fields: schema = form_field.interface if schema is None: continue data = schema_data.get(schema) if data is None: data = schema_data[schema] = {} if form_field.__name__ in form_data: data[form_field.field.__name__] = form_data[form_field.__name__] # Now validate the individual schemas errors = [] for schema, data in schema_data.items(): try: schema.validateInvariants(FormData(schema, data, context), errors) except interface.Invalid: pass # Just collect the errors return [error for error in errors if not isinstance(error, NoInputData)]
def checkInvariants(form_fields, form_data, context): # First, collect the data for the various schemas schema_data = {} for form_field in form_fields: schema = form_field.interface if schema is None: continue data = schema_data.get(schema) if data is None: data = schema_data[schema] = {} if form_field.__name__ in form_data: data[form_field.field.__name__] = form_data[form_field.__name__] # Now validate the individual schemas errors = [] for schema, data in schema_data.items(): try: schema.validateInvariants(FormData(schema, data, context), errors) except interface.Invalid: pass # Just collect the errors return [error for error in errors if not isinstance(error, NoInputData)]
def validate_invariants(self, errors=[] ): '''Return <errors>''' #errors = [] obj = self.obj schema = obj.get_schema() #log1.debug('\n\n IN VALIDATE INVARIANTS obj is %s\n\n', obj) # Descend into field invariants recurse = False try: recurse = schema.getTaggedValue('recurse-on-invariants') except KeyError: pass if recurse: for k, field in obj.iter_fields(): f = field.get(obj) ef = self._validate_invariants_for_field(f, field) #log1.debug('\n\n IN INNER VALIDATE k is %s, field is %s, f is %s, ef is %s\n\n', k, field, f ,ef) if ef: errors.append(ef) # Check own invariants try: ef = [] schema.validateInvariants(obj, ef) except zope.interface.Invalid: errors.append(ef) return errors