Make human-friendly the name of the dump files and xut some long lines
parent
df20fc7f45
commit
8c6588b17a
|
@ -65,10 +65,10 @@ class ProjectExporterViewSet(mixins.ImportThrottlingPolicyMixin, GenericViewSet)
|
||||||
|
|
||||||
if settings.CELERY_ENABLED:
|
if settings.CELERY_ENABLED:
|
||||||
task = tasks.dump_project.delay(request.user, project)
|
task = tasks.dump_project.delay(request.user, project)
|
||||||
tasks.delete_project_dump.apply_async((project.pk,), countdown=settings.EXPORTS_TTL)
|
tasks.delete_project_dump.apply_async((project.pk, project.slug), countdown=settings.EXPORTS_TTL)
|
||||||
return Response({"export-id": task.id}, status=status.HTTP_202_ACCEPTED)
|
return Response({"export-id": task.id}, status=status.HTTP_202_ACCEPTED)
|
||||||
|
|
||||||
path = "exports/{}/{}.json".format(project.pk, uuid.uuid4().hex)
|
path = "exports/{}/{}-{}.json".format(project.pk, project.slug, uuid.uuid4().hex)
|
||||||
content = ContentFile(ExportRenderer().render(service.project_to_dict(project),
|
content = ContentFile(ExportRenderer().render(service.project_to_dict(project),
|
||||||
renderer_context={"indent": 4}).decode('utf-8'))
|
renderer_context={"indent": 4}).decode('utf-8'))
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ class ProjectExporterViewSet(mixins.ImportThrottlingPolicyMixin, GenericViewSet)
|
||||||
}
|
}
|
||||||
return Response(response_data, status=status.HTTP_200_OK)
|
return Response(response_data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class ProjectImporterViewSet(mixins.ImportThrottlingPolicyMixin, CreateModelMixin, GenericViewSet):
|
class ProjectImporterViewSet(mixins.ImportThrottlingPolicyMixin, CreateModelMixin, GenericViewSet):
|
||||||
model = Project
|
model = Project
|
||||||
permission_classes = (permissions.ImportExportPermission, )
|
permission_classes = (permissions.ImportExportPermission, )
|
||||||
|
|
|
@ -33,32 +33,41 @@ from .renderers import ExportRenderer
|
||||||
@app.task(bind=True)
|
@app.task(bind=True)
|
||||||
def dump_project(self, user, project):
|
def dump_project(self, user, project):
|
||||||
mbuilder = MagicMailBuilder()
|
mbuilder = MagicMailBuilder()
|
||||||
|
path = "exports/{}/{}-{}.json".format(project.pk, project.slug, self.request.id)
|
||||||
path = "exports/{}/{}.json".format(project.pk, self.request.id)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
content = ContentFile(ExportRenderer().render(project_to_dict(project), renderer_context={"indent": 4}).decode('utf-8'))
|
content = ExportRenderer().render(project_to_dict(project), renderer_context={"indent": 4})
|
||||||
|
content = content.decode('utf-8')
|
||||||
|
content = ContentFile(content)
|
||||||
|
|
||||||
default_storage.save(path, content)
|
default_storage.save(path, content)
|
||||||
url = default_storage.url(path)
|
url = default_storage.url(path)
|
||||||
except Exception:
|
except Exception:
|
||||||
email = mbuilder.export_import_error(
|
ctx = {
|
||||||
user.email,
|
|
||||||
{
|
|
||||||
"user": user,
|
"user": user,
|
||||||
"error_subject": "Error generating project dump",
|
"error_subject": "Error generating project dump",
|
||||||
"error_message": "Error generating project dump",
|
"error_message": "Error generating project dump",
|
||||||
}
|
}
|
||||||
)
|
email = mbuilder.export_import_error(user.email, ctx)
|
||||||
email.send()
|
email.send()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
deletion_date = timezone.now() + datetime.timedelta(seconds=settings.EXPORTS_TTL)
|
deletion_date = timezone.now() + datetime.timedelta(seconds=settings.EXPORTS_TTL)
|
||||||
email = mbuilder.dump_project(user.email, {"url": url, "project": project, "user": user, "deletion_date": deletion_date})
|
ctx = {
|
||||||
|
"url": url,
|
||||||
|
"project": project,
|
||||||
|
"user": user,
|
||||||
|
"deletion_date": deletion_datei
|
||||||
|
}
|
||||||
|
email = mbuilder.dump_project(user.email, ctx)
|
||||||
email.send()
|
email.send()
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def delete_project_dump(project_id, task_id):
|
def delete_project_dump(project_id, project_slug, task_id):
|
||||||
default_storage.delete("exports/{}/{}.json".format(project_id, task_id))
|
default_storage.delete("exports/{}/{}-{}.json".format(project_id, project_slug, task_id))
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def load_project_dump(user, dump):
|
def load_project_dump(user, dump):
|
||||||
|
|
Loading…
Reference in New Issue