#NEWLINE# def _validate_config_helper( session , config , name_col , id_col , id_value , meta_table , metafield_table , patch = True ) : #NEWLINE# #INDENT# with session . begin ( subtransactions = True ) : #NEWLINE# #INDENT# for elem in config : #NEWLINE# #INDENT# obj = session . query ( meta_table ) . filter ( ( name_col == elem ) ) . filter ( or_ ( ( id_col is None ) , ( id_col == id_value ) ) ) . first ( ) #NEWLINE# if ( ( not obj ) and ( '_type' not in config [ elem ] ) ) : #NEWLINE# #INDENT# return ( False , ( "Invalid metadata '%s'!" % elem ) ) #NEWLINE# #UNINDENT# if ( '_type' in config [ elem ] ) : #NEWLINE# #INDENT# metadata_name = config [ elem ] [ '_type' ] #NEWLINE# obj = session . query ( meta_table ) . filter_by ( name = metadata_name ) . first ( ) #NEWLINE# if ( not obj ) : #NEWLINE# #INDENT# err_msg = ( "Invalid metatdata '%s' or missing '_type'to indicate this is a variable metatdata." % elem ) #NEWLINE# return ( False , err_msg ) #NEWLINE# #UNINDENT# del config [ elem ] [ '_type' ] #NEWLINE# #UNINDENT# fields = obj . fields #NEWLINE# if ( not fields ) : #NEWLINE# #INDENT# ( is_valid , message ) = _validate_config_helper ( session , config [ elem ] , name_col , id_col , id_value , meta_table , metafield_table , patch ) #NEWLINE# if ( not is_valid ) : #NEWLINE# #INDENT# return ( False , message ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# field_config = config [ elem ] #NEWLINE# for key in field_config : #NEWLINE# #INDENT# field = session . query ( metafield_table ) . filter_by ( field = key ) . first ( ) #NEWLINE# if ( not field ) : #NEWLINE# #INDENT# return ( False , ( "Invalid field '%s'!" % key ) ) #NEWLINE# #UNINDENT# value = field_config [ key ] #NEWLINE# if ( field . is_required and ( value is None ) ) : #NEWLINE# #INDENT# err = ( "The value of field '%s' cannot be null!" % key ) #NEWLINE# return ( False , err ) #NEWLINE# #UNINDENT# if field . validator : #NEWLINE# #INDENT# func = getattr ( validator , field . validator ) #NEWLINE# if ( ( not err_msg ) or ( not func ( value ) ) ) : #NEWLINE# #INDENT# err_msg = ( "The value of the field '%s' is invalid format or None!" % key ) #NEWLINE# return ( False , err_msg ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not patch ) : #NEWLINE# #INDENT# for field in fields : #NEWLINE# #INDENT# name = field . field #NEWLINE# if ( field . is_required and ( name not in field_config ) ) : #NEWLINE# #INDENT# return ( False , ( "Missing required field '%s'" % name ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( True , None )