From 4a786baf4edb688477f701e8d9b12b5d12c96166 Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Fri, 12 Nov 2021 17:32:22 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=B7=A5=E5=8D=95=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=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 | 11 ++++++++--- .../ticket/meta/ticket_type/apply_asset.py | 7 +++++-- 2 files changed, 13 insertions(+), 5 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 c3f75ed6d..98e303b1c 100644 --- a/apps/tickets/serializers/ticket/meta/ticket_type/apply_application.py +++ b/apps/tickets/serializers/ticket/meta/ticket_type/apply_application.py @@ -77,14 +77,19 @@ class ApplySerializer(serializers.Serializer): type = self.root.initial_data['meta'].get('apply_type') org_id = self.root.initial_data.get('org_id') with tmp_to_org(org_id): - applications = Application.objects.filter(id__in=apply_applications, type=type).values_list('id', flat=True) + applications = Application.objects.filter( + id__in=apply_applications, type=type + ).values_list('id', flat=True) return list(applications) def validate(self, attrs): - apply_date_start = attrs['apply_date_start'] - apply_date_expired = attrs['apply_date_expired'] + apply_date_start = attrs['apply_date_start'].strftime('%Y-%m-%d %H:%M:%S') + apply_date_expired = attrs['apply_date_expired'].strftime('%Y-%m-%d %H:%M:%S') if apply_date_expired <= apply_date_start: error = _('The expiration date should be greater than the start date') raise serializers.ValidationError({'apply_date_expired': error}) + + attrs['apply_date_start'] = apply_date_start + attrs['apply_date_expired'] = apply_date_expired return attrs diff --git a/apps/tickets/serializers/ticket/meta/ticket_type/apply_asset.py b/apps/tickets/serializers/ticket/meta/ticket_type/apply_asset.py index a4b78e7d5..19da551ec 100644 --- a/apps/tickets/serializers/ticket/meta/ticket_type/apply_asset.py +++ b/apps/tickets/serializers/ticket/meta/ticket_type/apply_asset.py @@ -64,10 +64,13 @@ class ApplySerializer(serializers.Serializer): )) def validate(self, attrs): - apply_date_start = attrs['apply_date_start'] - apply_date_expired = attrs['apply_date_expired'] + apply_date_start = attrs['apply_date_start'].strftime('%Y-%m-%d %H:%M:%S') + apply_date_expired = attrs['apply_date_expired'].strftime('%Y-%m-%d %H:%M:%S') if apply_date_expired <= apply_date_start: error = _('The expiration date should be greater than the start date') raise serializers.ValidationError({'apply_date_expired': error}) + + attrs['apply_date_start'] = apply_date_start + attrs['apply_date_expired'] = apply_date_expired return attrs