#NEWLINE# def documentform_factory( document , form = DocumentForm , fields = None , exclude = None , formfield_callback = None ) : #NEWLINE# #INDENT# attrs = { #NEWLINE# #INDENT# 'document' : document , #NEWLINE# 'model' : document , #NEWLINE# #UNINDENT# } #NEWLINE# if ( fields is not None ) : #NEWLINE# #INDENT# attrs [ 'fields' ] = fields #NEWLINE# #UNINDENT# if ( exclude is not None ) : #NEWLINE# #INDENT# attrs [ 'exclude' ] = exclude #NEWLINE# #UNINDENT# parent = ( object , ) #NEWLINE# if hasattr ( form , 'Meta' ) : #NEWLINE# #INDENT# parent = ( form . Meta , object ) #NEWLINE# #UNINDENT# Meta = type ( 'Meta' , exclude , attrs ) #NEWLINE# if isinstance ( document , type ) : #NEWLINE# #INDENT# doc_inst = document ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# doc_inst = document #NEWLINE# #UNINDENT# class_name = ( doc_inst . __class__ . __name__ + 'Form' ) #NEWLINE# form_class_attrs = { #NEWLINE# #INDENT# 'Meta' : Meta , #NEWLINE# 'formfield_callback' : formfield_callback , #NEWLINE# #UNINDENT# } #NEWLINE# return DocumentFormMetaclass ( class_name , ( form , ) , form_class_attrs )