<commit_before># -*- coding: utf-8 -*-

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core import validators
from django.core.mail import send_mail
from django.conf import settings
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager, Group
from django.utils import timezone

from core.utils import hash_name
import re


class AbstractTimtecUser(AbstractBaseUser, PermissionsMixin):
    USERNAME_REGEXP = 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_REGEXP, _('Enter a valid username.'), 'invalid')
        ])

    first_name = models.CharField(_('First name'), max_length=30, blank=True)
    last_name = models.CharField(_('Last name'), max_length=30, blank=True)
    is_staff = models.BooleanField(_('Staff status'), default=False)
    is_active = models.BooleanField(_('Active'), default=True)
    date_joined = models.DateTimeField(_('Date joined'), default=timezone.now)

    picture = models.ImageField(_("Picture"), upload_to=hash_name('user-pictures', 'username'), blank=True)
    occupation = models.CharField(_('Occupation'), max_length=30, blank=True)
    city = models.CharField(_('City'), max_length=30, blank=True)
    site = models.URLField(_('Site'), blank=True)
    biography = models.TextField(_('Biography'), blank=True)
    accepted_terms = models.BooleanField(_('Accepted terms and condition'), default=False)

    objects = UserManager()

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

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')
        abstract = True

    def __unicode__(self):
        if self.first_name or self.last_name:
            return self.get_full_name()
        return self.email

    def get_picture_url(self):
        if not self.picture:
            location = "/%s/%s" % (settings.STATIC_URL, 'img/avatar-default.png')
        else:
            location = "/%s/%s" % (settings.MEDIA_URL, self.picture)
        return re.sub('/+', '/', location)

    def get_full_name(self):
        full_name = '%s %s' % (self.first_name, self.last_name)
        return full_name.strip()

    def get_short_name(self):
        return self.first_name

    def email_user(self, subject, message, from_email=None):
        send_mail(subject, message, from_email, [self.email])

    def get_user_type(self):
        if self.is_superuser:
            return "superuser"
        elif self.groups.filter(name='professors').count():
            return "professors"
        elif self.groups.filter(name='students').count():
            return "students"
        return "unidentified"

    def is_pilot(self):
        return self.groups.filter(name='pilot_course').count() > 0

    def save(self, *args, **kwargs):

        is_new = self.pk is None

        super(AbstractTimtecUser, self).save(*args, **kwargs)

        if is_new and settings.REGISTRATION_DEFAULT_GROUP_NAME:
            try:
                self.groups.add(Group.objects.get(name=settings.REGISTRATION_DEFAULT_GROUP_NAME))
                self.save()
            except models.exceptions.ObjectDoesNotExist:
                pass


class TimtecUser(AbstractTimtecUser):
    """
    Timtec customized user.

    Username, password and email are required. Other fields are optional.
    """

    email = models.EmailField(_('Email address'), blank=False, unique=True)

    class Meta(AbstractTimtecUser.Meta):
        swappable = 'AUTH_USER_MODEL'<commit_msg>necessary fields added to TimtecUser Model<commit_after># -*- coding: utf-8 -*-

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core import validators
from django.core.mail import send_mail
from django.conf import settings
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager, Group
from django.utils import timezone

from core.utils import hash_name
import re


class AbstractTimtecUser(AbstractBaseUser, PermissionsMixin):
    USERNAME_REGEXP = 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_REGEXP, _('Enter a valid username.'), 'invalid')
        ])

    first_name = models.CharField(_('First name'), max_length=30, blank=True)
    last_name = models.CharField(_('Last name'), max_length=30, blank=True)
    is_staff = models.BooleanField(_('Staff status'), default=False)
    is_active = models.BooleanField(_('Active'), default=True)
    date_joined = models.DateTimeField(_('Date joined'), default=timezone.now)

    picture = models.ImageField(_("Picture"), upload_to=hash_name('user-pictures', 'username'), blank=True)
    occupation = models.CharField(_('Occupation'), max_length=30, blank=True)
    city = models.CharField(_('City'), max_length=30, blank=True)
    site = models.URLField(_('Site'), blank=True)
    biography = models.TextField(_('Biography'), blank=True)
    accepted_terms = models.BooleanField(_('Accepted terms and condition'), default=False)

    objects = UserManager()

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

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')
        abstract = True

    def __unicode__(self):
        if self.first_name or self.last_name:
            return self.get_full_name()
        return self.email

    def get_picture_url(self):
        if not self.picture:
            location = "/%s/%s" % (settings.STATIC_URL, 'img/avatar-default.png')
        else:
            location = "/%s/%s" % (settings.MEDIA_URL, self.picture)
        return re.sub('/+', '/', location)

    def get_full_name(self):
        full_name = '%s %s' % (self.first_name, self.last_name)
        return full_name.strip()

    def get_short_name(self):
        return self.first_name

    def email_user(self, subject, message, from_email=None):
        send_mail(subject, message, from_email, [self.email])

    def get_user_type(self):
        if self.is_superuser:
            return "superuser"
        elif self.groups.filter(name='professors').count():
            return "professors"
        elif self.groups.filter(name='students').count():
            return "students"
        return "unidentified"

    def is_pilot(self):
        return self.groups.filter(name='pilot_course').count() > 0

    def save(self, *args, **kwargs):

        is_new = self.pk is None

        super(AbstractTimtecUser, self).save(*args, **kwargs)

        if is_new and settings.REGISTRATION_DEFAULT_GROUP_NAME:
            try:
                self.groups.add(Group.objects.get(name=settings.REGISTRATION_DEFAULT_GROUP_NAME))
                self.save()
            except models.exceptions.ObjectDoesNotExist:
                pass



#populated by fixture
class State (models.Model):
    name = models.CharField(max_length=50)
    uf = models.CharField(max_length=2,primary_key=True)
    uf_code = models.CharField(max_length=5)

#populated by fixture
class City (models.Model):
    code = models.CharField(max_length=20)
    name = models.CharField(max_length=80)
    uf = models.ForeignKey(State, on_delete=models.CASCADE)


#populated by fixture
class Discipline (models.Model):
    name = models.CharField(max_length=200, unique=True,primary_key=True)

    def __str__(self):
        return self.name



class School (models.Model):
    name = models.CharField(max_length=200)
    school_type = models.CharField(max_length=30, blank=True, null=True)  #private or public
    city = models.ForeignKey(City, blank=True, null=True)
    education_degree = models.CharField(max_length=50, blank=True, null=True)

#populated by fixture
class EducationDegree (models.Model):
    name = models.CharField(max_length=70,primary_key=True)

class TimtecUser(AbstractTimtecUser):
    """
    Timtec customized user.

    Username, password and email are required. Other fields are optional.
    """
    business_email = models.EmailField(blank=True, null=True)
    email = models.EmailField(_('Email address'), blank=False, unique=True)
    level_of_education_taught = models.ManyToManyField(EducationDegree, blank=True, null=True)
    school = models.ManyToManyField(School, blank=True, null=True)
    disciplines = models.ManyToManyField(Discipline, blank=True, null=True)
    city = City
    state = models.CharField(max_length=50, blank=True, null=True)
    job_title = models.CharField(max_length=70, blank=True, null=True)

    class Meta(AbstractTimtecUser.Meta):
        swappable = 'AUTH_USER_MODEL'
{'fraction_non_alphanumeric': 0.1200223089793642, 'fraction_numerical': 0.005800334634690463, 'mean_word_length': 3.410231185440236, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6228985', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2655, 'n_words': 579}