#NEWLINE# @ atomic ( ) #NEWLINE# def import_data( self , dataset , dry_run = False , raise_errors = False , use_transactions = None , **kwargs ) : #NEWLINE# #INDENT# '\n        Imports data from ``tablib.Dataset``. Refer to :doc:`import_workflow`\n        for a more complete description of the whole import process.\n\n        :param dataset: A ``tablib.Dataset``\n\n        :param raise_errors: Whether errors should be printed to the end user\n            or raised regularly.\n\n        :param use_transactions: If ``True`` import process will be processed\n            inside transaction.\n\n        :param dry_run: If ``dry_run`` is set, or error occurs, transaction\n            will be rolled back.\n        ' #NEWLINE# result = self . get_result_class ( ) ( ) #NEWLINE# result . diff_headers = self . get_diff_headers ( ) #NEWLINE# result . totals = OrderedDict ( [ ( RowResult . IMPORT_TYPE_NEW , 0 ) , ( RowResult . IMPORT_TYPE_UPDATE , 0 ) , ( RowResult . IMPORT_TYPE_DELETE , 0 ) , ( RowResult . IMPORT_TYPE_SKIP , 0 ) , ( RowResult . IMPORT_TYPE_ERROR , 0 ) , ( 'total' , len ( dataset ) ) ] ) #NEWLINE# if ( use_transactions is None ) : #NEWLINE# #INDENT# use_transactions = self . get_use_transactions ( ) #NEWLINE# #UNINDENT# if ( use_transactions is True ) : #NEWLINE# #INDENT# real_dry_run = False #NEWLINE# sp1 = savepoint ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# real_dry_run = dry_run #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . before_import ( dataset , real_dry_run , ** kwargs ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logging . exception ( e ) #NEWLINE# tb_info = traceback . format_exc ( ) #NEWLINE# result . base_errors . append ( self . get_error_result_class ( ) ( e , tb_info ) ) #NEWLINE# if raise_errors : #NEWLINE# #INDENT# if use_transactions : #NEWLINE# #INDENT# savepoint_rollback ( self ) #NEWLINE# #UNINDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# instance_loader = self . _meta . instance_loader_class ( self , dataset ) #NEWLINE# result . totals [ 'total' ] = len ( dataset ) #NEWLINE# for row in dataset . dict : #NEWLINE# #INDENT# row_result = self . import_row ( row , instance_loader , real_dry_run , ** kwargs ) #NEWLINE# if row_result . errors : #NEWLINE# #INDENT# result . totals [ row_result . IMPORT_TYPE_ERROR ] += 1 #NEWLINE# if raise_errors : #NEWLINE# #INDENT# if use_transactions : #NEWLINE# #INDENT# savepoint_rollback ( sp1 ) #NEWLINE# #UNINDENT# raise row_result . errors [ ( - 1 ) ] . error #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# result . totals [ row_result . import_type ] += 1 #NEWLINE# #UNINDENT# if ( ( row_result . import_type != RowResult . IMPORT_TYPE_SKIP ) or self . _meta . report_skipped ) : #NEWLINE# #INDENT# result . rows . append ( row_result ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# self . after_import ( dataset , result , real_dry_run , ** kwargs ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logging . exception ( e ) #NEWLINE# tb_info = traceback . format_exc ( ) #NEWLINE# result . base_errors . append ( self . get_error_result_class ( ) ( e , tb_info ) ) #NEWLINE# if raise_errors : #NEWLINE# #INDENT# if use_transactions : #NEWLINE# #INDENT# savepoint_rollback ( sp1 ) #NEWLINE# #UNINDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# if use_transactions : #NEWLINE# #INDENT# if ( dry_run or result . has_errors ( ) ) : #NEWLINE# #INDENT# savepoint_rollback ( sp1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# savepoint_commit ( sp1 ) #NEWLINE# #UNINDENT# #UNINDENT# return result