write_to_tmp_storage() for import_action() (#781)
* Function to handle writing data for import_action * Updated AUTHORS
This commit is contained in:
parent
9dceba914e
commit
816b49c23a
3
AUTHORS
3
AUTHORS
|
@ -104,5 +104,6 @@ The following is a list of much appreciated contributors:
|
|||
* pacotole (Pacotole)
|
||||
* KenyaDonDraper
|
||||
* andrew-bro (Andrei Loskutov)
|
||||
* toivomattila (Toivo Mattila)
|
||||
* ZuluPro (Anthony Monthe)
|
||||
* kunal15595 (Kunal Khandelwal)
|
||||
* kunal15595 (Kunal Khandelwal)
|
|
@ -218,6 +218,15 @@ class ImportMixin(ImportExportMixinBase):
|
|||
'''
|
||||
return ImportForm
|
||||
|
||||
def write_to_tmp_storage(self, import_file, input_format):
|
||||
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())
|
||||
return tmp_storage
|
||||
|
||||
def import_action(self, request, *args, **kwargs):
|
||||
'''
|
||||
Perform a dry_run of the import to make sure the import will not
|
||||
|
@ -242,12 +251,7 @@ class ImportMixin(ImportExportMixinBase):
|
|||
import_file = form.cleaned_data['import_file']
|
||||
# first always write the uploaded file to disk as it may be a
|
||||
# memory file or else based on settings upload handlers
|
||||
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())
|
||||
tmp_storage = self.write_to_tmp_storage(import_file, input_format)
|
||||
|
||||
# then read the file, using the proper format-specific mode
|
||||
# warning, big files may exceed memory
|
||||
|
|
Loading…
Reference in New Issue