本文整理汇总了Python中temba.contacts.models.ContactField.is_valid_label方法的典型用法代码示例。如果您正苦于以下问题:Python ContactField.is_valid_label方法的具体用法?Python ContactField.is_valid_label怎么用?Python ContactField.is_valid_label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类temba.contacts.models.ContactField
的用法示例。
在下文中一共展示了ContactField.is_valid_label方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean
# 需要导入模块: from temba.contacts.models import ContactField [as 别名]
# 或者: from temba.contacts.models.ContactField import is_valid_label [as 别名]
def clean(self):
for key in self.cleaned_data:
if key.startswith('field_'):
idx = key[6:]
label = self.cleaned_data["label_%s" % idx]
if label:
if not ContactField.is_valid_label(label):
raise forms.ValidationError(_("Field names can only contain letters, numbers, spaces and hypens"))
elif label in RESERVED_CONTACT_FIELDS:
raise forms.ValidationError(_("Field name '%s' is a reserved word") % label)
return self.cleaned_data
示例2: clean
# 需要导入模块: from temba.contacts.models import ContactField [as 别名]
# 或者: from temba.contacts.models.ContactField import is_valid_label [as 别名]
def clean(self):
# don't allow users to specify field keys or labels
re_col_name_field = re.compile(r'column_\w+_label')
for key, value in self.data.items():
if re_col_name_field.match(key):
field_label = value
field_key = slugify_with(value)
if not ContactField.is_valid_label(field_label):
raise ValidationError(_("Field names can only contain letters, numbers, spaces and hypens"))
if field_key in RESERVED_CONTACT_FIELDS:
raise ValidationError(_("%s is a reserved name for contact fields") % value)
return self.cleaned_data
示例3: clean
# 需要导入模块: from temba.contacts.models import ContactField [as 别名]
# 或者: from temba.contacts.models.ContactField import is_valid_label [as 别名]
def clean(self):
used_labels = []
for key in self.cleaned_data:
if key.startswith('field_'):
idx = key[6:]
label = self.cleaned_data["label_%s" % idx]
if label:
if not ContactField.is_valid_label(label):
raise forms.ValidationError(_("Field names can only contain letters, numbers and hypens"))
if label.lower() in used_labels:
raise ValidationError(_("Field names must be unique"))
elif label in Contact.RESERVED_FIELDS:
raise forms.ValidationError(_("Field name '%s' is a reserved word") % label)
used_labels.append(label.lower())
return self.cleaned_data
示例4: validate_label
# 需要导入模块: from temba.contacts.models import ContactField [as 别名]
# 或者: from temba.contacts.models.ContactField import is_valid_label [as 别名]
def validate_label(self, value):
if value and not ContactField.is_valid_label(value):
raise serializers.ValidationError("Field can only contain letters, numbers and hypens")
return value