mirror of
https://github.com/ae-utbm/sith.git
synced 2026-11-05 08:49:32 +00:00
check email toxic domain at model-level
This commit is contained in:
1 parent
4f989d82bb
commit
e980c4d727
7 files changed
+31
-9
No files matched your search
+2
-2
@@ -2,7 +2,7 @@ from django import forms
|
||||
from django.core.validators import EmailValidator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from antispam.models import ToxicDomain
|
||||
from antispam.models.models import ToxicDomain
|
||||
|
||||
|
||||
class AntiSpamEmailValidator(EmailValidator):
|
||||
@@ -17,6 +17,6 @@ validate_antispam_email = AntiSpamEmailValidator()
|
||||
|
||||
|
||||
class AntiSpamEmailField(forms.EmailField):
|
||||
"""An email field that email addresses with a known toxic domain."""
|
||||
"""An email field that forbids email addresses with a known toxic domain."""
|
||||
|
||||
default_validators = [validate_antispam_email]
|
||||
@@ -0,0 +1,4 @@
|
||||
from antispam.models.fields import AntiSpamEmailField
|
||||
from antispam.models.models import ToxicDomain
|
||||
|
||||
__all__ = ["AntiSpamEmailField", "ToxicDomain"]
|
||||
@@ -0,0 +1,21 @@
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
from antispam import forms
|
||||
|
||||
|
||||
class AntiSpamEmailField(models.EmailField):
|
||||
"""An email field that forbids email addresses with a known toxic domain."""
|
||||
|
||||
default_validators = [forms.validate_antispam_email]
|
||||
|
||||
|
||||
if settings.TESTING:
|
||||
from model_bakery import baker
|
||||
|
||||
baker.generators.add(
|
||||
AntiSpamEmailField, lambda: baker.random_gen.gen_email(max_length=100)
|
||||
)
|
||||
else: # pragma: no cover
|
||||
# baker is only used in tests, so we don't need coverage for this part
|
||||
pass
|
||||
File renamed without changes.
Whitespace-only changes.
Reference in new issue
Block a user