forked from github/plane
fix: bulk modules importer (#973)
This commit is contained in:
parent
21992f540f
commit
b2ad071608
@ -487,48 +487,59 @@ class BulkImportModulesEndpoint(BaseAPIView):
|
|||||||
ignore_conflicts=True,
|
ignore_conflicts=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
_ = ModuleLink.objects.bulk_create(
|
modules = Module.objects.filter(id__in=[module.id for module in modules])
|
||||||
[
|
|
||||||
ModuleLink(
|
|
||||||
module=module,
|
|
||||||
url=module_data.get("link", {}).get("url", "https://plane.so"),
|
|
||||||
title=module_data.get("link", {}).get(
|
|
||||||
"title", "Original Issue"
|
|
||||||
),
|
|
||||||
project_id=project_id,
|
|
||||||
workspace_id=project.workspace_id,
|
|
||||||
created_by=request.user,
|
|
||||||
updated_by=request.user,
|
|
||||||
)
|
|
||||||
for module, module_data in zip(modules, modules_data)
|
|
||||||
],
|
|
||||||
batch_size=100,
|
|
||||||
ignore_conflicts=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
bulk_module_issues = []
|
if len(modules) == len(modules_data):
|
||||||
for module, module_data in zip(modules, modules_data):
|
_ = ModuleLink.objects.bulk_create(
|
||||||
module_issues_list = module_data.get("module_issues_list", [])
|
[
|
||||||
bulk_module_issues = bulk_module_issues + [
|
ModuleLink(
|
||||||
ModuleIssue(
|
module=module,
|
||||||
issue_id=issue,
|
url=module_data.get("link", {}).get(
|
||||||
module=module,
|
"url", "https://plane.so"
|
||||||
project_id=project_id,
|
),
|
||||||
workspace_id=project.workspace_id,
|
title=module_data.get("link", {}).get(
|
||||||
created_by=request.user,
|
"title", "Original Issue"
|
||||||
updated_by=request.user,
|
),
|
||||||
)
|
project_id=project_id,
|
||||||
for issue in module_issues_list
|
workspace_id=project.workspace_id,
|
||||||
]
|
created_by=request.user,
|
||||||
|
updated_by=request.user,
|
||||||
|
)
|
||||||
|
for module, module_data in zip(modules, modules_data)
|
||||||
|
],
|
||||||
|
batch_size=100,
|
||||||
|
ignore_conflicts=True,
|
||||||
|
)
|
||||||
|
|
||||||
_ = ModuleIssue.objects.bulk_create(
|
bulk_module_issues = []
|
||||||
bulk_module_issues, batch_size=100, ignore_conflicts=True
|
for module, module_data in zip(modules, modules_data):
|
||||||
)
|
module_issues_list = module_data.get("module_issues_list", [])
|
||||||
|
bulk_module_issues = bulk_module_issues + [
|
||||||
|
ModuleIssue(
|
||||||
|
issue_id=issue,
|
||||||
|
module=module,
|
||||||
|
project_id=project_id,
|
||||||
|
workspace_id=project.workspace_id,
|
||||||
|
created_by=request.user,
|
||||||
|
updated_by=request.user,
|
||||||
|
)
|
||||||
|
for issue in module_issues_list
|
||||||
|
]
|
||||||
|
|
||||||
serializer = ModuleSerializer(modules, many=True)
|
_ = ModuleIssue.objects.bulk_create(
|
||||||
return Response(
|
bulk_module_issues, batch_size=100, ignore_conflicts=True
|
||||||
{"modules": serializer.data}, status=status.HTTP_201_CREATED
|
)
|
||||||
)
|
|
||||||
|
serializer = ModuleSerializer(modules, many=True)
|
||||||
|
return Response(
|
||||||
|
{"modules": serializer.data}, status=status.HTTP_201_CREATED
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return Response(
|
||||||
|
{"message": "Modules created but issues could not be imported"},
|
||||||
|
status=status.HTTP_200_OK,
|
||||||
|
)
|
||||||
except Project.DoesNotExist:
|
except Project.DoesNotExist:
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Project does not exist"}, status=status.HTTP_404_NOT_FOUND
|
{"error": "Project does not exist"}, status=status.HTTP_404_NOT_FOUND
|
||||||
|
Loading…
Reference in New Issue
Block a user