check email toxic domain at model-level

This commit is contained in:
imperosol committed 2026-10-31 18:50:04 +01:00
1 parent 4f989d82bb
commit e980c4d727
7 files changed
+31 -9

No files matched your search

+21
View File
@@ -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