fix: 解决playbook 上传500的问题 (#9580)

Co-authored-by: Aaron3S <chenyang@fit2cloud.com>
pull/9584/head
fit2bot 2023-02-16 15:36:54 +08:00 committed by GitHub
parent eae4f76e1f
commit e84411588a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -5,6 +5,7 @@ from rest_framework import serializers
from common.serializers.fields import ReadableHiddenField from common.serializers.fields import ReadableHiddenField
from ops.models import Playbook from ops.models import Playbook
from orgs.mixins.serializers import BulkOrgResourceModelSerializer from orgs.mixins.serializers import BulkOrgResourceModelSerializer
from django.utils.translation import gettext_lazy as _
def parse_playbook_name(path): def parse_playbook_name(path):
@ -15,13 +16,13 @@ def parse_playbook_name(path):
class PlaybookSerializer(BulkOrgResourceModelSerializer): class PlaybookSerializer(BulkOrgResourceModelSerializer):
creator = ReadableHiddenField(default=serializers.CurrentUserDefault()) creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
path = serializers.FileField(required=False) path = serializers.FileField(required=False)
name = serializers.CharField(label=_('Name'), max_length=128, allow_blank=True, required=False)
def create(self, validated_data): def to_internal_value(self, data):
name = validated_data.get('name') name = data.get('name', False)
if not name: if not name:
path = validated_data.get('path').name data['name'] = parse_playbook_name(data['path'].name)
validated_data['name'] = parse_playbook_name(path) return super().to_internal_value(data)
return super().create(validated_data)
class Meta: class Meta:
model = Playbook model = Playbook