-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring/user model #67
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b23b1e6
Refactoring User_Model
xxfeel 5e937b0
Add django-phonenumber-field
xxfeel 5e196c8
Merge branch 'dev' into refactoring/User_model
xxfeel d5015ca
bugfix of mypy/added django-extensions 3.2.3
xxfeel ffebb7f
merge dev
xxfeel 50fe786
resolve conflicts
KonstantinRaikhert 24be247
fix flake8 mypy errors
KonstantinRaikhert e563248
fix django extensions/
KonstantinRaikhert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай тогда сразу добавим shell +
https://django-extensions.readthedocs.io/en/latest/shell_plus.html
Обрати внимание что эти пакеты в dev)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Извини, не понял какие пакеты ты имеешь ввиду
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
имеется ввиду django-extensions, так есть более удобный инструмент shell_plus.
Ну чтобы они не уходили эти пакеты в прод, а остались в дев)
Может конечно очевидно, но решил напомнить
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нет, всё в порядке) показалось что открылась документация