From 864d5640e3e9b2452d8aec04399042724d27b2eb Mon Sep 17 00:00:00 2001 From: Dan Braghis <dan.braghis@torchbox.com> Date: Wed, 28 Feb 2018 12:00:14 +0000 Subject: [PATCH] Add missing methods on our custom user --- opentech/apply/users/models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/opentech/apply/users/models.py b/opentech/apply/users/models.py index e69cf921f..e9e4b96f1 100644 --- a/opentech/apply/users/models.py +++ b/opentech/apply/users/models.py @@ -1,10 +1,12 @@ from django.db import models from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin +from django.core.mail import send_mail from django.utils import timezone from django.utils.translation import gettext_lazy as _ from .utils import send_activation_email + class UserManager(BaseUserManager): use_in_migrations = True @@ -74,8 +76,16 @@ class User(AbstractBaseUser, PermissionsMixin): def __str__(self): return self.get_full_name() + def clean(self): + super().clean() + self.email = self.__class__.objects.normalize_email(self.email) + def get_full_name(self): return self.full_name.strip() def get_short_name(self): return self.email + + def email_user(self, subject, message, from_email=None, **kwargs): + """Send an email to this user.""" + send_mail(subject, message, from_email, [self.email], **kwargs) -- GitLab