示例#1
0
def instance_object(fields=[], filters=(), validators=Instance._validations, **instance):
    instance = filter_fields(instance, filters)
    validators['instance_data'] = create_instance_validators(fields)
    instance['schema_id'] = uuid.UUID(instance.get('schema_id', ''))
    instance['table_id'] = uuid.UUID(instance.get('table_id', ''))
    instance = Instance(**instance)
    instance.validate(validators)
    instance._validations = validators
    if (hasattr(instance, 'validation_errors') 
        and instance.validation_errors) \
    or instance.instance_data.get('validation_errors', {}): 
        instance.validation_errors = dict(instance.validation_errors.items() + instance.instance_data.get('validation_errors', {}).items())
        raise BadRequestError('Validations failed: '+ str(instance.validation_errors))
    if instance.instance_data.has_key('validation_errors'):
        del instance.instance_data['validation_errors']
    return instance
示例#2
0
def local_type(verifield, type_name):
    """ Checks if a field conforms to the local table definition, which is basically a join/sub-object

    :param type_name: URI of the tenant.schema.table Ids that would be reference of the object to validate against
    :type type_name: URI
    :returns: bool
    """
    from polyglot.pyapi.meta import retrieve_schema_table_fields
    from polyglot.pyapi.instance import create_instance_validators
    from polyglot.models.schema import Instance
    (tenant_id, schema_id, table_id) = type_name.split("::")
    fields = retrieve_schema_table_fields(tenant_id, schema_id, table_id)
    validators = Instance._validations
    validators['instance_data'] = create_instance_validators(fields)
    instance = Instance(**instance)
    instance.validate(validators)
    instance._validations = validators
    return not((hasattr(instance, 'validation_errors') 
        and instance.validation_errors) \
    or instance.instance_data.get('validation_errors', {}))