Merge pull request #10718 from jumpserver/pr@dev@perf_phone

perf: 优化 phone
pull/10719/head
老广 2023-06-14 20:23:59 +08:00 committed by GitHub
commit d87ece00bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -214,8 +214,11 @@ class BitChoicesField(TreeChoicesField):
class PhoneField(serializers.CharField):
def to_representation(self, value):
if value:
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