#NEWLINE# def process_ajax_references( references , view ) : #NEWLINE# #INDENT# def make_name( base , name ) : #NEWLINE# #INDENT# if base : #NEWLINE# #INDENT# return ( '%s-%s' % ( base , name ) ) . lower ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return as_unicode ( name ) . lower ( ) #NEWLINE# #UNINDENT# #UNINDENT# def handle_field( field , subdoc , base ) : #NEWLINE# #INDENT# ftype = type ( field ) . __name__ #NEWLINE# if ( ( ftype == 'ListField' ) or ( ftype == 'SortedListField' ) ) : #NEWLINE# #INDENT# child_doc = getattr ( subdoc , '_form_subdocuments' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( None ) #NEWLINE# if child_doc : #NEWLINE# #INDENT# handle_field ( field . field , child_doc , base ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ftype == 'EmbeddedDocumentField' ) : #NEWLINE# #INDENT# result = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ajax_refs = getattr ( subdoc , 'form_ajax_refs' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# for ( field_name , opts ) in iteritems ( ajax_refs ) : #NEWLINE# #INDENT# child_name = make_name ( base , field_name ) #NEWLINE# if isinstance ( opts , dict ) : #NEWLINE# #INDENT# loader = create_ajax_loader ( field . document_type_obj , child_name , field_name , opts ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# loader = opts #NEWLINE# #UNINDENT# result [ field_name ] = loader #NEWLINE# references [ child_name ] = loader #NEWLINE# #UNINDENT# subdoc . _form_ajax_refs = result #NEWLINE# child_doc = getattr ( subdoc , '_form_subdocuments' , None ) #NEWLINE# if child_doc : #NEWLINE# #INDENT# handle_subdoc ( field . document_type_obj , subdoc , base ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Failed to process subdocument field %s' % ( field , ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# def handle_subdoc( model , subdoc , base ) : #NEWLINE# #INDENT# documents = getattr ( subdoc , '_form_subdocuments' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# for ( name , doc ) in iteritems ( documents ) : #NEWLINE# #INDENT# field = getattr ( model , name , None ) #NEWLINE# if ( not field ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Invalid subdocument field %s.%s' % ( model , name ) ) ) #NEWLINE# #UNINDENT# handle_field ( field , doc , make_name ( base , name ) ) #NEWLINE# #UNINDENT# #UNINDENT# handle_subdoc ( view . model , view , '' ) #NEWLINE# return handle_field