Exemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.fields['email'].validators.extend(
         (validators.HTML5EmailValidator(),
          validators.validate_confusables_email,
          validators.CaseInsensitiveUnique(models.User, 'email',
                                           validators.DUPLICATE_EMAIL)))
     self.fields['email'].required = True
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        email_field = User.get_email_field_name()
        self.fields[email_field].validators.extend((
            validators.HTML5EmailValidator(),
            validators.validate_confusables_email,
            validators.CaseInsensitiveUnique(User, email_field,
                                             "This email is unavailable"),
        ))
        self.label_suffix = ""

        # This overrides the default labels set by UserCreationForm
        for field, label in self._meta.labels.items():
            self.fields[field].label = label

        for field in self._meta.fields:
            self.fields[field].required = True
Exemplo n.º 3
0
    def test_email_validator(self):
        """
        Test the HTMl5 email address validator.

        """
        validator = validators.HTML5EmailValidator()
        for value in (
                "*****@*****.**",
                "*****@*****.**",
                "*****@*****.**",
                "*****@*****.**",
        ):
            self.assertTrue(validator(value) is None)
        for value in (
                "@@@example.com",
                "test:test@[email protected]",
                'test"test@example"*****@*****.**',
        ):
            with self.assertRaisesMessage(ValidationError,
                                          str(validator.message)):
                validator(value)