mirror of https://github.com/jumpserver/jumpserver
fix: 修复用户导入时手机号为dict类型报错的问题
parent
11464151e2
commit
896cb061ab
|
@ -212,6 +212,23 @@ class BitChoicesField(TreeChoicesField):
|
|||
|
||||
|
||||
class PhoneField(serializers.CharField):
|
||||
|
||||
def to_internal_value(self, data):
|
||||
if isinstance(data, dict):
|
||||
code = data.get('code')
|
||||
phone = data.get('phone', '')
|
||||
if code and phone:
|
||||
data = '{}{}'.format(code, phone)
|
||||
else:
|
||||
data = phone
|
||||
try:
|
||||
phone = phonenumbers.parse(data, 'CN')
|
||||
data = '{}{}'.format(phone.country_code, phone.national_number)
|
||||
except phonenumbers.NumberParseException:
|
||||
data = '+86{}'.format(data)
|
||||
|
||||
return super().to_internal_value(data)
|
||||
|
||||
def to_representation(self, value):
|
||||
if value:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue