Skip to content

Commit eff3578

Browse files
committed
Rework user.models imports
1 parent c06b15c commit eff3578

1 file changed

Lines changed: 19 additions & 35 deletions

File tree

users/models.py

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,8 @@
55
from django_stubs_ext.db.models import TypedModelMeta
66
from django.contrib.contenttypes.fields import GenericRelation
77

8-
from users.constants import (
9-
ADMIN,
10-
EXPERT,
11-
INVESTOR,
12-
MEMBER,
13-
MENTOR,
14-
VERBOSE_ROLE_TYPES,
15-
VERBOSE_USER_TYPES,
16-
COUNT_LANGUAGES_VALIDATION_MESSAGE,
17-
UNIQUE_LANGUAGES_VALIDATION_MESSAGE,
18-
USER_MAX_LANGUAGES_COUNT,
19-
USER_EXPERIENCE_YEAR_VALIDATION_MESSAGE,
20-
OnboardingStage,
21-
UserEducationLevels,
22-
UserEducationStatuses,
23-
UserLanguagesEnum,
24-
UserLanguagesLevels,
25-
)
8+
from users import constants
9+
2610
from users.managers import (
2711
CustomUserManager,
2812
UserAchievementManager,
@@ -70,11 +54,11 @@ class CustomUser(AbstractUser):
7054
the `v2_speciality` and `skills`.
7155
"""
7256

73-
ADMIN = ADMIN
74-
MEMBER = MEMBER
75-
MENTOR = MENTOR
76-
EXPERT = EXPERT
77-
INVESTOR = INVESTOR
57+
ADMIN = constants.ADMIN
58+
MEMBER = constants.MEMBER
59+
MENTOR = constants.MENTOR
60+
EXPERT = constants.EXPERT
61+
INVESTOR = constants.INVESTOR
7862

7963
username = None
8064
email = models.EmailField(unique=True)
@@ -83,7 +67,7 @@ class CustomUser(AbstractUser):
8367
password = models.CharField(max_length=255)
8468
is_active = models.BooleanField(default=False, editable=False)
8569
user_type = models.PositiveSmallIntegerField(
86-
choices=VERBOSE_USER_TYPES,
70+
choices=constants.VERBOSE_USER_TYPES,
8771
default=get_default_user_type,
8872
)
8973
ordering_score = models.PositiveIntegerField(
@@ -144,7 +128,7 @@ class CustomUser(AbstractUser):
144128
null=True,
145129
blank=True,
146130
editable=False,
147-
default=OnboardingStage.intro.value,
131+
default=constants.OnboardingStage.intro.value,
148132
verbose_name="Стадия онбординга",
149133
help_text="0, 1, 2 - номера стадий онбординга, null(пустое) - онбординг пройден",
150134
)
@@ -268,11 +252,11 @@ class AbstractUserWithRole(models.Model):
268252
"""
269253

270254
first_additional_role = models.PositiveSmallIntegerField(
271-
choices=VERBOSE_ROLE_TYPES,
255+
choices=constants.VERBOSE_ROLE_TYPES,
272256
null=True,
273257
)
274258
second_additional_role = models.PositiveSmallIntegerField(
275-
choices=VERBOSE_ROLE_TYPES,
259+
choices=constants.VERBOSE_ROLE_TYPES,
276260
null=True,
277261
)
278262

@@ -494,7 +478,7 @@ def clean(self) -> None:
494478
super().clean()
495479
if self.entry_year and self.completion_year:
496480
if self.entry_year > self.completion_year:
497-
raise ValidationError(USER_EXPERIENCE_YEAR_VALIDATION_MESSAGE)
481+
raise ValidationError(constants.USER_EXPERIENCE_YEAR_VALIDATION_MESSAGE)
498482

499483
def save(self, *args, **kwargs):
500484
self.clean()
@@ -525,14 +509,14 @@ class UserEducation(AbstractUserExperience):
525509
)
526510
education_level = models.CharField(
527511
max_length=256,
528-
choices=UserEducationLevels.choices(),
512+
choices=constants.UserEducationLevels.choices(),
529513
blank=True,
530514
null=True,
531515
verbose_name="Уровень образования",
532516
)
533517
education_status = models.CharField(
534518
max_length=256,
535-
choices=UserEducationStatuses.choices(),
519+
choices=constants.UserEducationStatuses.choices(),
536520
blank=True,
537521
null=True,
538522
verbose_name="Статус по обучению",
@@ -594,12 +578,12 @@ class UserLanguages(models.Model):
594578
)
595579
language = models.CharField(
596580
max_length=50,
597-
choices=UserLanguagesEnum.choices(),
581+
choices=constants.UserLanguagesEnum.choices(),
598582
verbose_name="Язык",
599583
)
600584
language_level = models.CharField(
601585
max_length=50,
602-
choices=UserLanguagesLevels.choices(),
586+
choices=constants.UserLanguagesLevels.choices(),
603587
verbose_name="Уровнь владения",
604588
)
605589

@@ -610,7 +594,7 @@ class Meta:
610594
models.UniqueConstraint(
611595
fields=["user", "language"],
612596
name="unique_user_language",
613-
violation_error_message=UNIQUE_LANGUAGES_VALIDATION_MESSAGE,
597+
violation_error_message=constants.UNIQUE_LANGUAGES_VALIDATION_MESSAGE,
614598
)
615599
]
616600

@@ -620,8 +604,8 @@ def clean(self) -> None:
620604
"""
621605
super().clean()
622606
user_languages = self.user.user_languages.values_list("language", flat=True)
623-
if (self.language not in user_languages) and len(user_languages) == USER_MAX_LANGUAGES_COUNT:
624-
raise ValidationError(COUNT_LANGUAGES_VALIDATION_MESSAGE)
607+
if (self.language not in user_languages) and len(user_languages) == constants.USER_MAX_LANGUAGES_COUNT:
608+
raise ValidationError(constants.COUNT_LANGUAGES_VALIDATION_MESSAGE)
625609

626610
def save(self, *args, **kwargs):
627611
self.clean()

0 commit comments

Comments
 (0)