Пример #1
0
    def clean_phone_numbers(self):
        """
        Expects a list of [{"phone_number": <phone number>}] as the value.
        """
        value = self.cleaned_data.get("phone_numbers")
        result = []
        try:
            value = json.loads(value)
            assert isinstance(value, list)
            for item in value:
                assert isinstance(item, dict)
                assert "phone_number" in item
                result.append(item["phone_number"])
        except (AssertionError, ValueError):
            raise ValidationError(_("Something went wrong. Please reload the "
                "page and try again."))

        if len(result) == 0:
            raise ValidationError(_("You must specify at least one phone"
                "number."))

        for phone_number in result:
            validate_phone_number(phone_number)

        return result
Пример #2
0
    def clean_phone_numbers(self):
        """
        Expects a list of [{"phone_number": <phone number>}] as the value.
        """
        value = self.cleaned_data.get("phone_numbers")
        result = []
        try:
            value = json.loads(value)
            assert isinstance(value, list)
            for item in value:
                assert isinstance(item, dict)
                assert "phone_number" in item
                result.append(item["phone_number"])
        except (AssertionError, ValueError):
            raise ValidationError(
                _("Something went wrong. Please reload the "
                  "page and try again."))

        if len(result) == 0:
            raise ValidationError(
                _("You must specify at least one phone"
                  "number."))

        for phone_number in result:
            validate_phone_number(phone_number)

        return result
Пример #3
0
def clean_phone_numbers(phone_numbers):
    cleaned_numbers = []
    for number in phone_numbers:
        if number:
            validate_phone_number(number,
                                  f'Invalid phone number detected: {number}')
            cleaned_numbers.append(number)
    return cleaned_numbers
Пример #4
0
 def clean_phone_numbers(self):
     value = self.cleaned_data.get('phone_numbers', '')
     phone_list = [strip_plus(s.strip()) for s in value.split(',')]
     phone_list = [phone for phone in phone_list if phone]
     if len(phone_list) == 0:
         raise ValidationError(_("This field is required."))
     for phone_number in phone_list:
         validate_phone_number(phone_number)
     return list(set(phone_list))
Пример #5
0
 def clean_phone_numbers(self):
     value = self.cleaned_data.get('phone_numbers', '')
     phone_list = [strip_plus(s.strip()) for s in value.split(',')]
     phone_list = [phone for phone in phone_list if phone]
     if len(phone_list) == 0:
         raise ValidationError(_("This field is required."))
     for phone_number in phone_list:
         validate_phone_number(phone_number)
     return list(set(phone_list))
Пример #6
0
 def clean_test_phone_number(self):
     value = self.cleaned_data.get('test_phone_number')
     value = apply_leniency(value)
     validate_phone_number(
         value,
         error_message=
         _("Please enter digits only, in international format (country code and phone number)."
           ))
     return value
Пример #7
0
 def validate_phone_number(self, phone_number: str) -> None:
     validate_phone_number(phone_number)
Пример #8
0
 def clean_test_phone_number(self):
     value = self.cleaned_data.get('test_phone_number')
     value = apply_leniency(value)
     validate_phone_number(value,
         error_message=_("Please enter digits only, in international format (country code and phone number)."))
     return value
Пример #9
0
 def clean_test_phone_number(self):
     value = self.cleaned_data.get('test_phone_number')
     validate_phone_number(value)
     return value