本文整理匯總了Python中temba.contacts.models.URN.validate方法的典型用法代碼示例。如果您正苦於以下問題:Python URN.validate方法的具體用法?Python URN.validate怎麽用?Python URN.validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類temba.contacts.models.URN
的用法示例。
在下文中一共展示了URN.validate方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: validate_urn
# 需要導入模塊: from temba.contacts.models import URN [as 別名]
# 或者: from temba.contacts.models.URN import validate [as 別名]
def validate_urn(value, strict=True):
try:
normalized = URN.normalize(value)
if strict and not URN.validate(normalized):
raise ValueError()
except ValueError:
raise serializers.ValidationError("Invalid URN: %s. Ensure phone numbers contain country codes." % value)
return normalized
示例2: to_internal_value
# 需要導入模塊: from temba.contacts.models import URN [as 別名]
# 或者: from temba.contacts.models.URN import validate [as 別名]
def to_internal_value(self, data):
try:
normalized = URN.normalize(data)
if not URN.validate(normalized):
raise ValueError()
except ValueError:
raise serializers.ValidationError("Invalid URN: %s. Ensure phone numbers contain country codes." % data)
return normalized
示例3: validate_urns
# 需要導入模塊: from temba.contacts.models import URN [as 別名]
# 或者: from temba.contacts.models.URN import validate [as 別名]
def validate_urns(self, value):
if value is not None:
self.parsed_urns = []
for urn in value:
try:
normalized = URN.normalize(urn)
scheme, path, query, display = URN.to_parts(normalized)
# for backwards compatibility we don't validate phone numbers here
if scheme != TEL_SCHEME and not URN.validate(normalized): # pragma: needs cover
raise ValueError()
except ValueError:
raise serializers.ValidationError("Invalid URN: '%s'" % urn)
self.parsed_urns.append(normalized)
return value
示例4: validate_urn
# 需要導入模塊: from temba.contacts.models import URN [as 別名]
# 或者: from temba.contacts.models.URN import validate [as 別名]
def validate_urn(self, value):
urns = []
if value:
# if we have tel URNs, we may need a country to normalize by
country = self.org.get_country_code()
for urn in value:
try:
normalized = URN.normalize(urn, country)
except ValueError as e: # pragma: needs cover
raise serializers.ValidationError(str(e))
if not URN.validate(normalized, country): # pragma: needs cover
raise serializers.ValidationError("Invalid URN: '%s'" % urn)
urns.append(normalized)
return urns
示例5: to_internal_value
# 需要導入模塊: from temba.contacts.models import URN [as 別名]
# 或者: from temba.contacts.models.URN import validate [as 別名]
def to_internal_value(self, data):
if not URN.validate(data):
raise ValidationError("Invalid URN: %s" % data)
return URN.normalize(data)