<commit_before>from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import BaseUserManager
from django.core.validators import validate_email

from django.core.exceptions import ValidationError
import re

class UserManager(BaseUserManager):
    def create_user(self, email, password, **kwargs):
        if not email:
            raise ValueError("User must have an email address")


        validate_email(email)
        self.validate_password(password)

        user = self.model(email = self.normalize_email(email))
        user.set_password(password)

        if "name" in kwargs:
            user.name = kwargs["name"]

        if "phonenumber" in kwargs:
            self.validate_phonenumber(kwargs["phonenumber"])
            user.phonenumber = kwargs["phonenumber"]

        if "is_admin" in kwargs and kwargs["is_admin"]:
            user.is_admin = True

        user.save(using = self._db)
        return user

    def validate_password(self, password):
        if len(password) < 6:
            raise ValidationError(("user password length should be at least 6"),
                                  code='invalid')
    def validate_phonenumber(self, phonenumber):
        if len(phonenumber) < 8:
            raise ValidationError(("user phonenumber length should be at least 8"),
                                  code='invalid')
        if not bool(re.match('^[0-9]$', phonenumber)):
            raise ValidationError(("user phonenumber should not be with character"))

class User(AbstractBaseUser):
    name = models.CharField(max_length = 20)
    email = models.EmailField(
                verbose_name = "Email Address",
                max_length = 50,
                unique = True,<commit_msg>add get_user method for user models<commit_after>from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import BaseUserManager
from django.core.validators import validate_email

from django.core.exceptions import ValidationError, ObjectDoesNotExist
import re

class UserManager(BaseUserManager):
    def create_user(self, email, password, **kwargs):
        if not email:
            raise ValueError("User must have an email address")


        validate_email(email)
        self.validate_password(password)

        user = self.model(email = self.normalize_email(email))
        user.set_password(password)

        if "name" in kwargs:
            user.name = kwargs["name"]

        if "phonenumber" in kwargs:
            self.validate_phonenumber(kwargs["phonenumber"])
            user.phonenumber = kwargs["phonenumber"]

        if "is_admin" in kwargs and kwargs["is_admin"]:
            user.is_admin = True

        user.save(using = self._db)
        return user

    def validate_password(self, password):
        if len(password) < 6:
            raise ValidationError(("user password length should be at least 6"),
                                  code='invalid')
    def validate_phonenumber(self, phonenumber):
        if len(phonenumber) < 8:
            raise ValidationError(("user phonenumber length should be at least 8"),
                                  code='invalid')
        if not bool(re.match('^[0-9]$', phonenumber)):
            raise ValidationError(("user phonenumber should not be with character"))

    def get_user(self, email):
        try:
            user = User.objects.get(email=email)
        except ObjectDoesNotExist:
            raise ObjectDoesNotExist("User has " + email + " email does not exist")

class User(AbstractBaseUser):
    name = models.CharField(max_length = 20)
    email = models.EmailField(
                verbose_name = "Email Address",
                max_length = 50,
                unique = True,
{'fraction_non_alphanumeric': 0.08961892247043364, 'fraction_numerical': 0.005256241787122208, 'mean_word_length': 2.4568574023614898, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2853070', 'n_tokens_mistral': 1030, 'n_tokens_neox': 988, 'n_words': 277}