'Perform a dry_run of the import to make sure the import will not
result in errors.  If there where no error, save the user
uploaded file to a local temp file that will be used by
\'process_import\' for the actual import.'

def import_action(self, request, *args, **kwargs):

    resource = self.get_import_resource_class()(**self.get_import_resource_kwargs(request, *args, **kwargs))
    context = self.get_import_context_data()
    import_formats = self.get_import_formats()
    form_type = self.get_import_form()
    form = form_type(import_formats, (request.POST or None), (request.FILES or None))
    if (request.POST and form.is_valid()):
        input_format = import_formats[int(form.cleaned_data['input_format'])]()
        import_file = form.cleaned_data['import_file']
        tmp_storage = self.get_tmp_storage_class()()
        data = bytes()
        for chunk in import_file.chunks():
            data += chunk
        tmp_storage.save(data, input_format.get_read_mode())
        try:
            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)
        except UnicodeDecodeError as e:
            return HttpResponse(_((u'<h1>Imported    file    has    a    wrong    encoding:    %s</h1>' % e)))
        except Exception as e:
            return HttpResponse(_((u'<h1>%s    encountered    while    trying    to    read    file:    %s</h1>' % (type(e).__name__, import_file.name))))
        result = resource.import_data(dataset, dry_run=True, raise_errors=False, file_name=import_file.name, user=request.user)
        context['result'] = result
        if (not result.has_errors()):
            context['confirm_form'] = ConfirmImportForm(initial={'import_file_name': tmp_storage.name, 'original_file_name': import_file.name, 'input_format': form.cleaned_data['input_format']})
    if (django.VERSION >= (1, 8, 0)):
        context.update(self.admin_site.each_context(request))
    elif (django.VERSION >= (1, 7, 0)):
        context.update(self.admin_site.each_context())
    context['title'] = _('Import')
    context['form'] = form
    context['opts'] = self.model._meta
    context['fields'] = [f.column_name for f in resource.get_user_visible_fields()]
    request.current_app = self.admin_site.name
    return TemplateResponse(request, [self.import_template_name], context)
