예제 #1
0
        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
예제 #2
0
        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
예제 #3
0
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)]
예제 #4
0
파일: form.py 프로젝트: kislovm/findburo
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)]
예제 #5
0
        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