mirror of https://github.com/jumpserver/jumpserver
perf: 优化 phone
parent
a3d32c901d
commit
fca3936a79
|
@ -214,8 +214,11 @@ class BitChoicesField(TreeChoicesField):
|
||||||
class PhoneField(serializers.CharField):
|
class PhoneField(serializers.CharField):
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
if value:
|
if value:
|
||||||
phone = phonenumbers.parse(value, 'CN')
|
try:
|
||||||
value = {'code': '+%s' % phone.country_code, 'phone': phone.national_number}
|
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
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue