From fca3936a79caf1b10b5afce101733678e7418990 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 14 Jun 2023 20:22:41 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20phone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/serializers/fields.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/common/serializers/fields.py b/apps/common/serializers/fields.py index e41a90944..cf92391e1 100644 --- a/apps/common/serializers/fields.py +++ b/apps/common/serializers/fields.py @@ -214,8 +214,11 @@ class BitChoicesField(TreeChoicesField): class PhoneField(serializers.CharField): def to_representation(self, value): if value: - phone = phonenumbers.parse(value, 'CN') - value = {'code': '+%s' % phone.country_code, 'phone': phone.national_number} + try: + phone = phonenumbers.parse(value, 'CN') + value = {'code': '+%s' % phone.country_code, 'phone': phone.national_number} + except phonenumbers.NumberParseException: + value = {'code': '+86', 'phone': value} return value