(self, request, *args, **kwargs)
Perform the actual import action (after the user has confirmed he
        wishes to import)
Perform the actual import action (after the user has confirmed he
        wishes to import)
Perform the actual import action ( after the user has confirmed he wishes to import )
def post(self, request, *args, **kwargs):
        """
        Perform the actual import action (after the user has confirmed he
        wishes to import)
        """
        resource = self.get_import_resource_class()(**self.get_import_resource_kwargs(request, *args, **kwargs))

        confirm_form = ConfirmImportForm(request.POST)
        if confirm_form.is_valid():
            import_formats = self.get_import_formats()
            input_format = import_formats[
                int(confirm_form.cleaned_data['input_format'])
            ]()
            tmp_storage = self.get_tmp_storage_class()(name=confirm_form.cleaned_data['import_file_name'])
            data = tmp_storage.read(input_format.get_read_mode())
            if not input_format.is_binary() and self.from_encoding:
                data = force_text(data, self.from_encoding)
            dataset = input_format.create_dataset(data)

            result = resource.import_data(dataset, dry_run=False,
                                          raise_errors=True,
                                          file_name=confirm_form.cleaned_data['original_file_name'],
                                          user=request.user)

            if not self.get_skip_admin_log():
                # Add imported objects to LogEntry
                logentry_map = {
                    RowResult.IMPORT_TYPE_NEW: ADDITION,
                    RowResult.IMPORT_TYPE_UPDATE: CHANGE,
                    RowResult.IMPORT_TYPE_DELETE: DELETION,
                }
                content_type_id = ContentType.objects.get_for_model(self.model).pk
                for row in result:
                    if row.import_type != row.IMPORT_TYPE_ERROR and row.import_type != row.IMPORT_TYPE_SKIP:
                        LogEntry.objects.log_action(
                            user_id=request.user.pk,
                            content_type_id=content_type_id,
                            object_id=row.object_id,
                            object_repr=row.object_repr,
                            action_flag=logentry_map[row.import_type],
                            change_message="%s through import_export" % row.import_type,
                        )
            success_message = str(_(u'Import finished')) + ' , ' + str(_(u'Add')) + ' : %d' % result.totals[
                RowResult.IMPORT_TYPE_NEW] + ' , ' + str(_(u'Update')) + ' : %d' % result.totals[
                RowResult.IMPORT_TYPE_UPDATE]

            messages.success(request, success_message)
            tmp_storage.remove()

            post_import.send(sender=None, model=self.model)
            model_info = (self.opts.app_label, self.opts.model_name)
            url = reverse('xadmin:%s_%s_changelist' % model_info,
                          current_app=self.admin_site.name)
            return HttpResponseRedirect(url)
def post ( self , request , * args , * * kwargs ) : resource = self . get_import_resource_class ( ) ( * * self . get_import_resource_kwargs ( request , * args , * * kwargs ) ) confirm_form = ConfirmImportForm ( request . POST ) if confirm_form . is_valid ( ) : import_formats = self . get_import_formats ( ) input_format = import_formats [ int ( confirm_form . cleaned_data [ 'input_format' ] ) ] ( ) tmp_storage = self . get_tmp_storage_class ( ) ( name = confirm_form . cleaned_data [ 'import_file_name' ] ) data = tmp_storage . read ( input_format . get_read_mode ( ) ) if not input_format . is_binary ( ) and self . from_encoding : data = force_text ( data , self . from_encoding ) dataset = input_format . create_dataset ( data ) result = resource . import_data ( dataset , dry_run = False , raise_errors = True , file_name = confirm_form . cleaned_data [ 'original_file_name' ] , user = request . user ) if not self . get_skip_admin_log ( ) : # Add imported objects to LogEntry logentry_map = { RowResult . IMPORT_TYPE_NEW : ADDITION , RowResult . IMPORT_TYPE_UPDATE : CHANGE , RowResult . IMPORT_TYPE_DELETE : DELETION , } content_type_id = ContentType . objects . get_for_model ( self . model ) . pk for row in result : if row . import_type != row . IMPORT_TYPE_ERROR and row . import_type != row . IMPORT_TYPE_SKIP : LogEntry . objects . log_action ( user_id = request . user . pk , content_type_id = content_type_id , object_id = row . object_id , object_repr = row . object_repr , action_flag = logentry_map [ row . import_type ] , change_message = "%s through import_export" % row . import_type , ) success_message = str ( _ ( u'Import finished' ) ) + ' , ' + str ( _ ( u'Add' ) ) + ' : %d' % result . totals [ RowResult . IMPORT_TYPE_NEW ] + ' , ' + str ( _ ( u'Update' ) ) + ' : %d' % result . totals [ RowResult . IMPORT_TYPE_UPDATE ] messages . success ( request , success_message ) tmp_storage . remove ( ) post_import . send ( sender = None , model = self . model ) model_info = ( self . opts . app_label , self . opts . model_name ) url = reverse ( 'xadmin:%s_%s_changelist' % model_info , current_app = self . admin_site . name ) return HttpResponseRedirect ( url )