Skip to content

Commit

Permalink
bugfix of mypy/added django-extensions 3.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
xxfeel committed Dec 18, 2023
1 parent 5e196c8 commit d5015ca
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 150 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ run:

# Запуск django shell
shell:
cd $(PROJECT_DIR) && $(DJANGO_RUN) shell
cd $(PROJECT_DIR) && $(DJANGO_RUN) shell_plus --plain


# Заполнение базы данных с помощью парсера.
fill-db:
cd $(PROJECT_DIR) && $(DJANGO_RUN) fill-db

.PHONY: help
.PHONY: help
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'main.apps.MainConfig',
'users.apps.UsersConfig',
'core.apps.CoreConfig',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Generated by Django 4.2.7 on 2023-12-18 05:27
# Generated by Django 4.2.8 on 2023-12-18 15:37

from django.db import migrations, models
import django.utils.timezone
import phonenumber_field.modelfields
import phonenumber_field.validators
import users.managers
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down Expand Up @@ -34,6 +37,11 @@ class Migration(migrations.Migration):
name='patronymic',
field=models.CharField(blank=True, help_text='Отчество', max_length=256, verbose_name='Отчество'),
),
migrations.AlterField(
model_name='user',
name='date_joined',
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Дата регистрации.'),
),
migrations.AlterField(
model_name='user',
name='email',
Expand All @@ -44,6 +52,16 @@ class Migration(migrations.Migration):
name='first_name',
field=models.CharField(help_text='Имя', max_length=256, verbose_name='Имя'),
),
migrations.AlterField(
model_name='user',
name='is_active',
field=models.BooleanField(default=True, verbose_name='Показывает статус он-лайн.'),
),
migrations.AlterField(
model_name='user',
name='is_staff',
field=models.BooleanField(default=False, verbose_name='Статус администратора.'),
),
migrations.AlterField(
model_name='user',
name='last_name',
Expand All @@ -52,7 +70,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='user',
name='phone',
field=models.CharField(max_length=12),
field=phonenumber_field.modelfields.PhoneNumberField(blank=True, help_text='Номер телефона, допустимый формат - +7 ХХХ ХХХ ХХ ХХ', max_length=128, region=None, validators=[phonenumber_field.validators.validate_international_phonenumber], verbose_name='Актуальный номер телефона'),
),
migrations.AlterField(
model_name='user',
Expand Down

This file was deleted.

33 changes: 27 additions & 6 deletions adaptive_hockey_federation/users/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from django.core.mail import send_mail
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from phonenumber_field.modelfields import PhoneNumberField
from phonenumber_field.validators import validate_international_phonenumber
Expand All @@ -17,13 +19,12 @@
from .managers import CustomUserManager


class User(AbstractUser):
class User(AbstractBaseUser, PermissionsMixin):
"""
Кастомная модель пользователя, поле 'username' исключено,
идентификатором является поле с адресом электронной почты.
"""

username = None
first_name = models.CharField(
max_length=NAME_MAX_LENGTH,
verbose_name=_('Имя'),
Expand Down Expand Up @@ -60,17 +61,34 @@ class User(AbstractUser):
verbose_name=_('Актуальный номер телефона'),
help_text=_('Номер телефона, допустимый формат - +7 ХХХ ХХХ ХХ ХХ'),
)

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ('first_name', 'last_name', 'role',)
date_joined = models.DateTimeField(
default=timezone.now,
verbose_name=_('Дата регистрации.'),
)
is_staff = models.BooleanField(
default=False,
verbose_name=_('Статус администратора.'),
)
is_active = models.BooleanField(
default=True,
verbose_name=_('Показывает статус он-лайн.'),
)

objects = CustomUserManager()

EMAIL_FIELD = "email"
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name', 'role']

class Meta:
verbose_name = _('Пользователь')
verbose_name_plural = _('Пользователи')
ordering = ('last_name',)

def clean(self):
super().clean()
self.email = self.__class__.objects.normalize_email(self.email)

def __str__(self):
return self.email[:QUERY_SET_LENGTH].capitalize()

Expand All @@ -87,6 +105,9 @@ def get_full_name(self):
f'{self.last_name[:QUERY_SET_LENGTH]}'
)

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

@property
def is_agent(self):
"""
Expand Down
Loading

0 comments on commit d5015ca

Please sign in to comment.