def bindClass( klass, mapper=None ): """ attach validation to a sqlalchemy mapped class, based on its implemented schemas, via property validators, taking care to wrap sqlalchemy properties. """ if mapper is None: mapper = getattr( klass, 'mapper') # compile the klass mapper, this will add instrumented attributes to the class # we could alternatively do.. mapper.compile() compiles all extant mappers mapper.compile() # find all the model schemas implemented by the class for iface in interface.implementedBy( klass ): if not IIModelInterface.providedBy( iface ): continue # for any field in the schema, see if we have an sa property for field_name in schema.getFieldNames( iface ): v = klass.__dict__.get( field_name ) # if so then wrap it in a field property if not isinstance( v, attributes.InstrumentedAttribute): continue field = iface[ field_name ] vproperty = ValidatedProperty( field, v, field_name ) setattr( klass, field_name, vproperty )
def bindClass( klass, mapper=None ): """ insert validated properties into a class based on its primary mapper, and model schemas """ # compile the klass mapper, this will add instrumented attributes to the class # we could alternatively do.. mapper.compile() compiles all extant mappers if mapper is None: mapper = getattr( klass, 'mapper') mapper.compile() # find all the model schemas implemented by the class for iface in providedByInstances( klass ): if not IIModelInterface.providedBy( iface ): continue # for any field in the schema, see if we have an sa property for field_name in schema.getFieldNames( iface ): v = klass.__dict__.get( field_name ) # if so then wrap it in a field property if not isinstance( v, attributes.InstrumentedAttribute): continue field = iface[ field_name ] vproperty = ValidatedProperty( field, v, field_name ) setattr( klass, field_name, vproperty )
def bindClass(klass, mapper=None): """ attach validation to a sqlalchemy mapped class, based on its implemented schemas, via property validators, taking care to wrap sqlalchemy properties. """ if mapper is None: mapper = getattr(klass, 'mapper') # compile the klass mapper, this will add instrumented attributes to the class # we could alternatively do.. mapper.compile() compiles all extant mappers mapper.compile() # find all the model schemas implemented by the class for iface in interface.implementedBy(klass): if not IIModelInterface.providedBy(iface): continue # for any field in the schema, see if we have an sa property for field_name in schema.getFieldNames(iface): v = klass.__dict__.get(field_name) # if so then wrap it in a field property if not isinstance(v, attributes.InstrumentedAttribute): continue field = iface[field_name] vproperty = ValidatedProperty(field, v, field_name) setattr(klass, field_name, vproperty)
def bindClass(klass, mapper=None): """ insert validated properties into a class based on its primary mapper, and model schemas """ # compile the klass mapper, this will add instrumented attributes to the class # we could alternatively do.. mapper.compile() compiles all extant mappers if mapper is None: mapper = getattr(klass, 'mapper') mapper.compile() # find all the model schemas implemented by the class for iface in providedByInstances(klass): if not IIModelInterface.providedBy(iface): continue # for any field in the schema, see if we have an sa property for field_name in schema.getFieldNames(iface): v = klass.__dict__.get(field_name) # if so then wrap it in a field property if not isinstance(v, attributes.InstrumentedAttribute): continue field = iface[field_name] vproperty = ValidatedProperty(field, v, field_name) setattr(klass, field_name, vproperty)
def queryModelInterface( klass ): """ we can passed in a class or interface """ if not IInterface.providedBy( klass ): candidates = list( interface.implementedBy( klass ) ) ifaces = filter( IIModelInterface.providedBy, candidates ) if not ifaces: for i in candidates: if issubclass( i, IAlchemistContent ): ifaces.append( i ) if not ifaces: raise SyntaxError( "No Model Interface on Domain Object" ) if ifaces: assert len(ifaces)==1, "Multiple Model Interfaces on Domain Object" klass = ifaces[0] else: assert IIModelInterface.providedBy( klass ), "Invalid Interface" return klass
def queryModelInterface(klass): """ we can passed in a class or interface """ if not IInterface.providedBy(klass): candidates = list(interface.implementedBy(klass)) ifaces = filter(IIModelInterface.providedBy, candidates) if not ifaces: for i in candidates: if issubclass(i, IAlchemistContent): ifaces.append(i) if not ifaces: raise SyntaxError("No Model Interface on Domain Object") if ifaces: assert len( ifaces) == 1, "Multiple Model Interfaces on Domain Object" klass = ifaces[0] else: assert IIModelInterface.providedBy(klass), "Invalid Interface" return klass