From faaefb9c5ccb7560e13a95f0fc12e19be7ce8b9e Mon Sep 17 00:00:00 2001 From: Maya Date: Mon, 31 May 2021 09:56:40 +0300 Subject: [PATCH] fix --- .../engine/migrations/0040_cloud_storage.py | 2 +- cvat/apps/engine/models.py | 2 +- cvat/apps/engine/views.py | 22 ++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cvat/apps/engine/migrations/0040_cloud_storage.py b/cvat/apps/engine/migrations/0040_cloud_storage.py index f6ef961a7e8a..c73609fd9fef 100644 --- a/cvat/apps/engine/migrations/0040_cloud_storage.py +++ b/cvat/apps/engine/migrations/0040_cloud_storage.py @@ -25,7 +25,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('provider_type', models.CharField(choices=[('AWS_S3_BUCKET', 'AWS_S3'), ('AZURE_CONTAINER', 'AZURE_CONTAINER'), ('GOOGLE_DRIVE', 'GOOGLE_DRIVE')], max_length=20)), ('resource', models.CharField(max_length=63)), - ('display_name', models.CharField(max_length=63, unique=True)), + ('display_name', models.CharField(max_length=63)), ('created_date', models.DateTimeField(auto_now_add=True)), ('updated_date', models.DateTimeField(auto_now=True)), ('credentials', models.CharField(max_length=500)), diff --git a/cvat/apps/engine/models.py b/cvat/apps/engine/models.py index cec4ebe73efe..f88f748aa689 100644 --- a/cvat/apps/engine/models.py +++ b/cvat/apps/engine/models.py @@ -581,7 +581,7 @@ class CloudStorage(models.Model): # The typical token size is less than 4096 bytes, but that can vary. provider_type = models.CharField(max_length=20, choices=CloudProviderChoice.choices()) resource = models.CharField(max_length=63) - display_name = models.CharField(max_length=63, unique=True) + display_name = models.CharField(max_length=63) owner = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL, related_name="cloud_storages") created_date = models.DateTimeField(auto_now_add=True) diff --git a/cvat/apps/engine/views.py b/cvat/apps/engine/views.py index 81aae1311b29..d1c8d866b1b1 100644 --- a/cvat/apps/engine/views.py +++ b/cvat/apps/engine/views.py @@ -25,7 +25,7 @@ from django_filters import rest_framework as filters from django_filters.rest_framework import DjangoFilterBackend from drf_yasg import openapi -from drf_yasg.inspectors import CoreAPICompatInspector, NotHandled +from drf_yasg.inspectors import CoreAPICompatInspector, NotHandled, FieldInspector from drf_yasg.utils import swagger_auto_schema from rest_framework import mixins, serializers, status, viewsets from rest_framework.decorators import action @@ -984,6 +984,15 @@ def self(self, request): serializer = serializer_class(request.user, context={ "request": request }) return Response(serializer.data) +class RedefineDescriptionField(FieldInspector): + # pylint: disable=no-self-use + def process_result(self, result, method_name, obj, **kwargs): + if isinstance(result, openapi.Schema): + if hasattr(result, 'title') and result.title == 'Specific attributes': + result.description = 'structure like key1=value1&key2=value2\n' \ + 'supported: range=aws_range' + return result + @method_decorator( name='retrieve', decorator=swagger_auto_schema( @@ -1004,8 +1013,9 @@ def self(self, request): openapi.Parameter('owner', openapi.IN_QUERY, description="A resource owner", type=openapi.TYPE_STRING), openapi.Parameter('credentials_type', openapi.IN_QUERY, description="A type of a granting access", type=openapi.TYPE_STRING, enum=CredentialsTypeChoice.list()), ], - responses={'200': CloudStorageSerializer(many=True)}, - tags=['cloud storages'] + responses={'200': BaseCloudStorageSerializer(many=True)}, + tags=['cloud storages'], + field_inspectors=[RedefineDescriptionField] ) ) @method_decorator(name='destroy', decorator=swagger_auto_schema( @@ -1015,7 +1025,8 @@ def self(self, request): ) @method_decorator(name='partial_update', decorator=swagger_auto_schema( operation_summary='Methods does a partial update of chosen fields in a cloud storage instance', - tags=['cloud storages'] + tags=['cloud storages'], + field_inspectors=[RedefineDescriptionField] ) ) class CloudStorageViewSet(auth.CloudStorageGetQuerySetMixin, viewsets.ModelViewSet): @@ -1092,7 +1103,8 @@ def perform_destroy(self, instance): responses={ '201': openapi.Response(description='A storage has beed created') }, - tags=['cloud storages'] + tags=['cloud storages'], + field_inspectors=[RedefineDescriptionField], ) ) def create(self, request, *args, **kwargs):