#NEWLINE# def prep_insert( self ) : #NEWLINE# #INDENT# '\n        Creates a INSERT statement that reorders and cleans up\n        the fields from the temporary table for insertion into the\n        Django model.\n\n        Returns SQL that can be run.\n        ' #NEWLINE# sql = '\n            INSERT INTO "%(model_table)s" (%(model_fields)s) (\n            SELECT %(temp_fields)s\n            FROM "%(temp_table)s");\n        ' #NEWLINE# options = dict ( model_table = self . model . _meta . db_table , temp_table = self . temp_table_name ) #NEWLINE# model_fields = [ ] #NEWLINE# for ( field , header ) in self . field_header_crosswalk : #NEWLINE# #INDENT# model_fields . append ( ( '"%s"' % field . get_attname_column ( ) [ 1 ] ) ) #NEWLINE# #UNINDENT# for k in self . static_mapping . keys ( ) : #NEWLINE# #INDENT# model_fields . append ( ( '"%s"' % k ) ) #NEWLINE# #UNINDENT# options [ 'model_fields' ] = ', ' . join ( model_fields ) #NEWLINE# temp_fields = [ ] #NEWLINE# for ( field , header ) in self . field_header_crosswalk : #NEWLINE# #INDENT# string = ( '"%s"' % header ) #NEWLINE# if hasattr ( field , 'copy_template' ) : #NEWLINE# #INDENT# string = ( field . copy_template % dict ( name = header ) ) #NEWLINE# #UNINDENT# template_method = ( 'copy_%s_template' % field . name ) #NEWLINE# if hasattr ( self . model , template_method ) : #NEWLINE# #INDENT# template = getattr ( self . model ( ) , template_method ) ( ) #NEWLINE# string = ( template % dict ( name = header ) ) #NEWLINE# #UNINDENT# temp_fields . append ( template_method ) #NEWLINE# #UNINDENT# for v in self . static_mapping . values ( ) : #NEWLINE# #INDENT# temp_fields . append ( ( "'%s'" % v ) ) #NEWLINE# #UNINDENT# options [ 'temp_fields' ] = ', ' . join ( temp_fields ) #NEWLINE# return ( sql % options )