<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
Alternative implementation of Django's authentication User model, which allows to authenticate
against the email field in addition to the username fields.
This alternative implementation is activated by setting ``AUTH_USER_MODEL = 'shop.User'`` in
settings.py, otherwise the default Django or another implementation is used.
"""
import re
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager
from django.core import validators
from django.core.mail import send_mail
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _


@python_2_unicode_compatible
class User(AbstractBaseUser, PermissionsMixin):
    """
    Alternative implementation of Django's User model allowing to authenticate
    against the email field in addition to the username field.
    """
    USERNAME_REGEX = re.compile('^[\w.@+-]+$')

    username = models.CharField(_("Username"), max_length=30, unique=True,
        help_text=_("Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters"),
        validators=[validators.RegexValidator(USERNAME_REGEX, _('Enter a valid username.'), 'invalid')])

    # copied from django.contrib.auth.models.AbstractUser
    first_name = models.CharField(_("First name"), max_length=30, blank=True)
    last_name = models.CharField(_("Last name"), max_length=30, blank=True)

    # this is the only field, which differs from the default implementation
    email = models.EmailField(_("Email address"), null=True, default=None, blank=True, unique=True, max_length=254)
    is_staff = models.BooleanField(_("staff status"), default=False,
        help_text=_("Designates whether the user can log into this admin site."))
    is_active = models.BooleanField(_("active"), default=True,
        help_text=_("Designates whether this user should be treated as active."
                    "Unselect this instead of deleting accounts."))
    date_joined = models.DateTimeField(_("date joined"), default=timezone.now)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']

    class Meta:
        db_table = 'auth_user'
        verbose_name = _("Customer")
        verbose_name_plural = _("Customers")

    def get_username(self):
        return self.email or '<anonymous>'

    def __str__(self):
        return self.get_username()

    def get_full_name(self):
        full_name = '{} {}'.format(self.first_name, self.last_name)
        full_name = full_name.strip()
        if full_name:
            return full_name
        return self.get_short_name()

    def get_short_name(self):
        if self.USERNAME_REGEX.match(self.username):
            return self.username
        return self.email

    def email_user(self, subject, message, from_email=None):
        send_mail(subject, message, from_email, [self.email])<commit_msg>Only show user.username for staff users<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
Alternative implementation of Django's authentication User model, which allows to authenticate
against the email field in addition to the username fields.
This alternative implementation is activated by setting ``AUTH_USER_MODEL = 'shop.User'`` in
settings.py, otherwise the default Django or another implementation is used.
"""
import re
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager
from django.core import validators
from django.core.mail import send_mail
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _


@python_2_unicode_compatible
class User(AbstractBaseUser, PermissionsMixin):
    """
    Alternative implementation of Django's User model allowing to authenticate
    against the email field in addition to the username field.
    """
    USERNAME_REGEX = re.compile('^[\w.@+-]+$')

    username = models.CharField(_("Username"), max_length=30, unique=True,
        help_text=_("Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters"),
        validators=[validators.RegexValidator(USERNAME_REGEX, _('Enter a valid username.'), 'invalid')])

    # copied from django.contrib.auth.models.AbstractUser
    first_name = models.CharField(_("First name"), max_length=30, blank=True)
    last_name = models.CharField(_("Last name"), max_length=30, blank=True)

    # this is the only field, which differs from the default implementation
    email = models.EmailField(_("Email address"), null=True, default=None, blank=True, unique=True, max_length=254)
    is_staff = models.BooleanField(_("staff status"), default=False,
        help_text=_("Designates whether the user can log into this admin site."))
    is_active = models.BooleanField(_("active"), default=True,
        help_text=_("Designates whether this user should be treated as active."
                    "Unselect this instead of deleting accounts."))
    date_joined = models.DateTimeField(_("date joined"), default=timezone.now)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']

    class Meta:
        db_table = 'auth_user'
        verbose_name = _("Customer")
        verbose_name_plural = _("Customers")

    def get_username(self):
        return self.email or '<anonymous>'

    def __str__(self):
        return self.get_username()

    def get_full_name(self):
        full_name = '{} {}'.format(self.first_name, self.last_name)
        full_name = full_name.strip()
        if full_name:
            return full_name
        return self.get_short_name()

    def get_short_name(self):
        if self.is_staff:
            return self.username
        if self.first_name:
            return self.first_name
        return self.email

    def email_user(self, subject, message, from_email=None):
        send_mail(subject, message, from_email, [self.email])
{'fraction_non_alphanumeric': 0.09986945169712794, 'fraction_numerical': 0.0045691906005221935, 'mean_word_length': 3.8604282315622522, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3583488', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1660, 'n_words': 502}