From 3ae8da231ac0b9f7efa3c17cf6ccccfb28c84d24 Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Thu, 28 Oct 2021 15:16:52 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=B7=A5=E5=8D=95=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ticket/meta/ticket_type/apply_application.py | 15 +++++++-------- apps/tickets/serializers/ticket/ticket.py | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/tickets/serializers/ticket/meta/ticket_type/apply_application.py b/apps/tickets/serializers/ticket/meta/ticket_type/apply_application.py index 46ef5386d..c3f75ed6d 100644 --- a/apps/tickets/serializers/ticket/meta/ticket_type/apply_application.py +++ b/apps/tickets/serializers/ticket/meta/ticket_type/apply_application.py @@ -80,12 +80,11 @@ class ApplySerializer(serializers.Serializer): applications = Application.objects.filter(id__in=apply_applications, type=type).values_list('id', flat=True) return list(applications) - def validate_apply_date_expired(self, value): - date_start = self.root.initial_data['meta'].get('apply_date_start') - date_start = datetime.strptime(date_start, '%Y-%m-%dT%H:%M:%S.%fZ') - date_expired = self.root.initial_data['meta'].get('apply_date_expired') - date_expired = datetime.strptime(date_expired, '%Y-%m-%dT%H:%M:%S.%fZ') - if date_expired <= date_start: + def validate(self, attrs): + apply_date_start = attrs['apply_date_start'] + apply_date_expired = attrs['apply_date_expired'] + + if apply_date_expired <= apply_date_start: error = _('The expiration date should be greater than the start date') - raise serializers.ValidationError(error) - return value + raise serializers.ValidationError({'apply_date_expired': error}) + return attrs diff --git a/apps/tickets/serializers/ticket/ticket.py b/apps/tickets/serializers/ticket/ticket.py index 82ac70122..636f06f4a 100644 --- a/apps/tickets/serializers/ticket/ticket.py +++ b/apps/tickets/serializers/ticket/ticket.py @@ -160,7 +160,7 @@ class TicketFlowApproveSerializer(serializers.ModelSerializer): def validate(self, attrs): if attrs['strategy'] == TicketApprovalStrategy.custom_user and not attrs.get('assignees'): error = _('Please select the Assignees') - raise serializers.ValidationError(error) + raise serializers.ValidationError({'assignees': error}) return super().validate(attrs)