From a37672812005fe74914d68ada33175e80e04ea59 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 17 Jan 2022 16:29:29 +0100 Subject: [PATCH] fixed keyword creation in exporter #1213 --- cookbook/integration/integration.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cookbook/integration/integration.py b/cookbook/integration/integration.py index 3b8034e37..6fee602c6 100644 --- a/cookbook/integration/integration.py +++ b/cookbook/integration/integration.py @@ -42,7 +42,7 @@ class Integration: try: last_kw = Keyword.objects.filter(name__regex=r'^(Import [0-9]+)', space=request.space).latest('created_at') name = f'Import {int(last_kw.name.replace("Import ", "")) + 1}' - except ObjectDoesNotExist: + except (ObjectDoesNotExist, ValueError): name = 'Import 1' parent, created = Keyword.objects.get_or_create(name='Import', space=request.space) @@ -53,7 +53,7 @@ class Integration: icon=icon, space=request.space ) - except IntegrityError: # in case, for whatever reason, the name does exist append UUID to it. Not nice but works for now. + except (IntegrityError, ValueError): # in case, for whatever reason, the name does exist append UUID to it. Not nice but works for now. self.keyword = parent.add_child( name=f'{name} {str(uuid.uuid4())[0:8]}', description=description, @@ -86,12 +86,10 @@ class Integration: export_obj.close() export_file = export_stream.getvalue() - response = HttpResponse(export_file, content_type='application/force-download') - response['Content-Disposition'] = 'attachment; filename="'+export_filename+'"' + response['Content-Disposition'] = 'attachment; filename="' + export_filename + '"' return response - def import_file_name_filter(self, zip_info_object): """ Since zipfile.namelist() returns all files in all subdirectories this function allows filtering of files @@ -262,7 +260,6 @@ class Integration: """ raise NotImplementedError('Method not implemented in integration') - def get_files_from_recipes(self, recipes, cookie): """ Takes a list of recipe object and converts it to a array containing each file.