update integration file split

This commit is contained in:
vabene1111
2021-03-28 19:49:03 +02:00
parent c1287407a3
commit e4a9f56352
3 changed files with 22 additions and 6 deletions

View File

@ -42,7 +42,7 @@ class Integration:
:return: HttpResponse with a ZIP file that is directly downloaded
"""
#TODO this is temporary, find a better solution for different export formats when doing other exporters
# TODO this is temporary, find a better solution for different export formats when doing other exporters
if self.export_type != ImportExportBase.RECIPESAGE:
export_zip_stream = BytesIO()
export_zip_obj = ZipFile(export_zip_stream, 'w')
@ -115,9 +115,9 @@ class Integration:
self.handle_duplicates(recipe, import_duplicates)
import_zip.close()
elif '.json' in f['name']:
json_data = json.loads(f['file'].read().decode("utf-8"))
for d in json_data:
elif '.json' in f['name'] or '.txt' in f['name']:
data_list = self.split_recipe_file(f['file'])
for d in data_list:
recipe = self.get_recipe_from_file(d)
recipe.keywords.add(self.keyword)
il.msg += f'{recipe.pk} - {recipe.name} \n'
@ -164,7 +164,15 @@ class Integration:
:param file: ByteIO or any file like object, depends on provider
:return: Recipe object
"""
raise NotImplementedError('Method not implemented in storage integration')
raise NotImplementedError('Method not implemented in integration')
def split_recipe_file(self, file):
"""
Takes a file that contains multiple recipes and splits it into a list of strings of various formats (e.g. json, text, ..)
:param file: ByteIO or any file like object, depends on provider
:return: list of strings
"""
raise NotImplementedError('Method not implemented in integration')
def get_file_from_recipe(self, recipe):
"""
@ -175,4 +183,4 @@ class Integration:
- name - file name in export
- data - string content for file to get created in export zip
"""
raise NotImplementedError('Method not implemented in storage integration')
raise NotImplementedError('Method not implemented in integration')