#NEWLINE# def fetch_data( self , handler = None , **kwargs ) : #NEWLINE# #INDENT# ' fill fields value ' #NEWLINE# handler = ( handler or self ) #NEWLINE# data = kwargs #NEWLINE# try : #NEWLINE# #INDENT# for ( key , field ) in self . _get_fields ( ) . items ( ) : #NEWLINE# #INDENT# if ( hasattr ( field , 'datatype' ) and isinstance ( field , ListField ) ) : #NEWLINE# #INDENT# vals = handler . get_arguments ( key , ( ) ) #NEWLINE# data [ key ] = field . val ( vals ) #NEWLINE# continue #NEWLINE# #UNINDENT# val = handler . get_argument ( key , data . get ( key , None ) ) #NEWLINE# if ( field . required and ( not val ) ) : #NEWLINE# #INDENT# raise Exception ( 'field {0} is required' . format ( key ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not val ) : #NEWLINE# #INDENT# if field . initial : #NEWLINE# #INDENT# data [ key ] = field . initial #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( field . pattern and ( not field . pattern . match ( val ) ) ) : #NEWLINE# #INDENT# raise Exception ( 'field {0}:{1} is not matched by {2}' . format ( key , val , field . pattern . pattern ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data [ key ] = field . val ( val ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# raise Exception ( '{0} in Model {1}' . format ( e . message , self . _name ) ) #NEWLINE# #UNINDENT# return data