예제 #1
0
    def validate_label(self, value):
        if not ContactField.is_valid_label(value):
            raise serializers.ValidationError("Can only contain letters, numbers and hypens.")

        key = ContactField.make_key(value)
        if not ContactField.is_valid_key(key):
            raise serializers.ValidationError("Generated key \"%s\" is invalid or a reserved name." % key)

        return value
예제 #2
0
    def validate_label(self, value):
        if not ContactField.is_valid_label(value):
            raise serializers.ValidationError("Can only contain letters, numbers and hypens.")

        key = ContactField.make_key(value)
        if not ContactField.is_valid_key(key):
            raise serializers.ValidationError("Generated key \"%s\" is invalid or a reserved name." % key)

        return value
예제 #3
0
    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
예제 #4
0
            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
예제 #5
0
            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
예제 #6
0
    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
예제 #7
0
파일: views.py 프로젝트: thierhost/rapidpro
    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
예제 #8
0
 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
예제 #9
0
 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