-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactoring User_Model * Add django-phonenumber-field * bugfix of mypy/added django-extensions 3.2.3 * fix flake8 mypy errors * fix django extensions/ --------- Co-authored-by: Konstantin Raikhert <raikhert13@gmail.com>
- Loading branch information
1 parent
1903717
commit e041655
Showing
16 changed files
with
365 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
NAME_MAX_LENGTH = 256 | ||
EMAIL_MAX_LENGTH = 256 | ||
QUERY_SET_LENGTH = 15 | ||
|
||
ROLE_AGENT = 'agent' | ||
ROLE_MODERATOR = 'moderator' | ||
ROLE_ADMIN = 'admin' | ||
ROLES_CHOICES = ( | ||
(ROLE_AGENT, 'Представитель команды'), | ||
(ROLE_MODERATOR, 'Модератор'), | ||
(ROLE_ADMIN, 'Администратор'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.contrib.auth.base_user import BaseUserManager | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class CustomUserManager(BaseUserManager): | ||
""" | ||
Кастомный менеджер модели пользователя, | ||
где идентификатором является поле с адресом электронной почты. | ||
""" | ||
|
||
use_in_migrations = True | ||
|
||
def _create_user(self, email, password, **extra_fields): | ||
if not email: | ||
raise ValueError(_('Предоставить адрес электронной почты.')) | ||
email = self.normalize_email(email) | ||
user = self.model(email=email, **extra_fields) | ||
user.set_password(password) | ||
user.save() | ||
return user | ||
|
||
def create_user(self, email, password=None, **extra_fields): | ||
extra_fields.setdefault('is_staff', False) | ||
extra_fields.setdefault('is_superuser', False) | ||
return self._create_user(email, password, **extra_fields) | ||
|
||
def create_superuser(self, email, password, **extra_fields): | ||
extra_fields.setdefault('is_staff', True) | ||
extra_fields.setdefault('is_superuser', True) | ||
extra_fields['role'] = 'admin' | ||
if extra_fields.get('is_staff') is not True: | ||
raise ValueError(_('Суперюзер должен иметь is_staff=True.')) | ||
if extra_fields.get('is_superuser') is not True: | ||
raise ValueError(_('Суперюзер должен иметь is_superuser=True.')) | ||
|
||
return self._create_user(email, password, **extra_fields) |
160 changes: 132 additions & 28 deletions
160
adaptive_hockey_federation/users/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,153 @@ | ||
# Generated by Django 4.2.6 on 2023-11-25 14:50 | ||
# Generated by Django 4.2.8 on 2023-12-19 14:34 | ||
|
||
import django.contrib.auth.models | ||
import django.contrib.auth.validators | ||
import django.db.models.deletion | ||
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): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('main', '0001_initial'), | ||
('auth', '0012_alter_user_first_name_max_length'), | ||
("auth", "0012_alter_user_first_name_max_length"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='User', | ||
name="User", | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('password', models.CharField(max_length=128, verbose_name='password')), | ||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), | ||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), | ||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), | ||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), | ||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), | ||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), | ||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), | ||
('phone', models.CharField(max_length=20)), | ||
('role', models.CharField(choices=[('user', 'Пользователь'), ('agent', 'Представитель команды'), ('moderator', 'Модератор'), ('admin', 'Администратор')], default='user', max_length=9)), | ||
('first_name', models.CharField(blank=True, max_length=256, null=True)), | ||
('last_name', models.CharField(blank=True, max_length=256, null=True)), | ||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), | ||
('team', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='users', to='main.team', verbose_name='Команда')), | ||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("password", models.CharField(max_length=128, verbose_name="password")), | ||
( | ||
"last_login", | ||
models.DateTimeField( | ||
blank=True, null=True, verbose_name="last login" | ||
), | ||
), | ||
( | ||
"is_superuser", | ||
models.BooleanField( | ||
default=False, | ||
help_text="Designates that this user has all permissions without explicitly assigning them.", | ||
verbose_name="superuser status", | ||
), | ||
), | ||
( | ||
"first_name", | ||
models.CharField( | ||
help_text="Имя", max_length=256, verbose_name="Имя" | ||
), | ||
), | ||
( | ||
"last_name", | ||
models.CharField( | ||
help_text="Фамилия", max_length=256, verbose_name="Фамилия" | ||
), | ||
), | ||
( | ||
"patronymic", | ||
models.CharField( | ||
blank=True, | ||
help_text="Отчество", | ||
max_length=256, | ||
verbose_name="Отчество", | ||
), | ||
), | ||
( | ||
"role", | ||
models.CharField( | ||
choices=[ | ||
("agent", "Представитель команды"), | ||
("moderator", "Модератор"), | ||
("admin", "Администратор"), | ||
], | ||
default="agent", | ||
help_text="Уровень прав доступа", | ||
max_length=9, | ||
verbose_name="Роль", | ||
), | ||
), | ||
( | ||
"email", | ||
models.EmailField( | ||
help_text="Электронная почта", | ||
max_length=256, | ||
unique=True, | ||
verbose_name="Электронная почта", | ||
), | ||
), | ||
( | ||
"phone", | ||
phonenumber_field.modelfields.PhoneNumberField( | ||
blank=True, | ||
help_text="Номер телефона, допустимый формат - +7 ХХХ ХХХ ХХ ХХ", | ||
max_length=128, | ||
region=None, | ||
validators=[ | ||
phonenumber_field.validators.validate_international_phonenumber | ||
], | ||
verbose_name="Актуальный номер телефона", | ||
), | ||
), | ||
( | ||
"date_joined", | ||
models.DateTimeField( | ||
default=django.utils.timezone.now, | ||
verbose_name="Дата регистрации.", | ||
), | ||
), | ||
( | ||
"is_staff", | ||
models.BooleanField( | ||
default=False, verbose_name="Статус администратора." | ||
), | ||
), | ||
( | ||
"is_active", | ||
models.BooleanField( | ||
default=True, verbose_name="Показывает статус он-лайн." | ||
), | ||
), | ||
( | ||
"groups", | ||
models.ManyToManyField( | ||
blank=True, | ||
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.", | ||
related_name="user_set", | ||
related_query_name="user", | ||
to="auth.group", | ||
verbose_name="groups", | ||
), | ||
), | ||
( | ||
"user_permissions", | ||
models.ManyToManyField( | ||
blank=True, | ||
help_text="Specific permissions for this user.", | ||
related_name="user_set", | ||
related_query_name="user", | ||
to="auth.permission", | ||
verbose_name="user permissions", | ||
), | ||
), | ||
], | ||
options={ | ||
'verbose_name': 'Пользователь', | ||
'verbose_name_plural': 'Пользователи', | ||
'ordering': ('username',), | ||
"verbose_name": "Пользователь", | ||
"verbose_name_plural": "Пользователи", | ||
"ordering": ("last_name",), | ||
}, | ||
managers=[ | ||
('objects', django.contrib.auth.models.UserManager()), | ||
("objects", users.managers.CustomUserManager()), | ||
], | ||
), | ||
] |
23 changes: 0 additions & 23 deletions
23
...ive_hockey_federation/users/migrations/0002_alter_user_first_name_alter_user_last_name.py
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
...ive_hockey_federation/users/migrations/0003_alter_user_first_name_alter_user_last_name.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.