Add methods from Django AbstractUser missing in Oscar AbstractUser
from django.conf import settings
from django.contrib.auth import models as auth_models
+from django.core.mail import send_mail
from django.core.validators import RegexValidator
from django.db import models
from django.template import TemplateDoesNotExist, engines
@@ -79,13 +80,29 @@ class AbstractUser(auth_models.AbstractBaseUser,
verbose_name = _('User')
verbose_name_plural = _('Users')
+ def clean(self):
+ super().clean()
+ self.email = self.__class__.objects.normalize_email(self.email)
+
def get_full_name(self):
+ """
+ Return the first_name plus the last_name, with a space in between.
+ """
full_name = '%s %s' % (self.first_name, self.last_name)
return full_name.strip()
def get_short_name(self):
+ """
+ Return the short name for the user.
+ """
return self.first_name
+ 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)
+
def _migrate_alerts_to_user(self):
"""
Transfer any active alerts linked to a user's email address to the
