Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Marishka17 committed May 31, 2021
1 parent 4ac72cc commit faaefb9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cvat/apps/engine/migrations/0040_cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 17 additions & 5 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit faaefb9

Please sign in to comment.