未验证 提交 6f887fc8 编写于 作者: M Maria Khrustaleva 提交者: GitHub

Add support any name for backup file (#91)

上级 54c15830
......@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed UX bug when jobs pagination is reset after changing a job (<https://github.com/cvat-ai/cvat/pull/42>)
- Progressbars in CLI for file uploading and downloading (<https://github.com/cvat-ai/cvat/pull/46>)
- `utils/cli` changed to `cvat-cli` package (<https://github.com/cvat-ai/cvat/pull/59>)
- Support custom file name for backup (<https://github.com/cvat-ai/cvat/pull/91>)
### Changed
- Bumped nuclio version to 1.8.14 (<https://github.com/cvat-ai/cvat/pull/29>)
......
......@@ -701,6 +701,8 @@ def _create_backup(db_instance, Exporter, output_path, logger, cache_ttl):
def export(db_instance, request):
action = request.query_params.get('action', None)
filename = request.query_params.get('filename', None)
if action not in (None, 'download'):
raise serializers.ValidationError(
"Unexpected action specified for the request")
......@@ -745,14 +747,14 @@ def export(db_instance, request):
timestamp = datetime.strftime(last_project_update_time,
"%Y_%m_%d_%H_%M_%S")
filename = "{}_{}_backup_{}{}".format(
filename = filename or "{}_{}_backup_{}{}".format(
filename_prefix, db_instance.name, timestamp,
os.path.splitext(file_path)[1])
os.path.splitext(file_path)[1]).lower()
location = location_conf.get('location')
if location == Location.LOCAL:
return sendfile(request, file_path, attachment=True,
attachment_filename=filename.lower())
attachment_filename=filename)
elif location == Location.CLOUD_STORAGE:
@validate_bucket_status
......
......@@ -487,6 +487,8 @@ class ProjectViewSet(viewsets.ModelViewSet, UploadMixin, AnnotationMixin, Serial
OpenApiParameter('action', location=OpenApiParameter.QUERY,
description='Used to start downloading process after backup file had been created',
type=OpenApiTypes.STR, required=False, enum=['download']),
OpenApiParameter('filename', description='Backup file name',
location=OpenApiParameter.QUERY, type=OpenApiTypes.STR, required=False),
OpenApiParameter('location', description='Where need to save downloaded backup',
location=OpenApiParameter.QUERY, type=OpenApiTypes.STR, required=False,
enum=Location.list()),
......@@ -707,6 +709,8 @@ class TaskViewSet(UploadMixin, AnnotationMixin, viewsets.ModelViewSet, Serialize
OpenApiParameter('action', location=OpenApiParameter.QUERY,
description='Used to start downloading process after backup file had been created',
type=OpenApiTypes.STR, required=False, enum=['download']),
OpenApiParameter('filename', description='Backup file name',
location=OpenApiParameter.QUERY, type=OpenApiTypes.STR, required=False),
OpenApiParameter('location', description='Where need to save downloaded backup',
location=OpenApiParameter.QUERY, type=OpenApiTypes.STR, required=False,
enum=Location.list()),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册