additional profile data
This commit is contained in:
parent
23544600c7
commit
84415f8d92
4 changed files with 75 additions and 14 deletions
|
|
@ -1,2 +1,20 @@
|
||||||
|
from django.db import models
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
MAX_OTP_TRY = 3
|
MAX_OTP_TRY = 3
|
||||||
DEVELOPMENT_PHONE_NUMBERS = ['+989999999999', '+989999999998']
|
DEVELOPMENT_PHONE_NUMBERS = ['+989999999999', '+989999999998']
|
||||||
|
|
||||||
|
class GenderChoices(models.TextChoices):
|
||||||
|
MALE = "m", _('male')
|
||||||
|
FEMALE = "f", _('female')
|
||||||
|
|
||||||
|
|
||||||
|
class EducationDegreeChoices(models.TextChoices):
|
||||||
|
PRIMARY_SCHOOL = 'primary', _('Primary school')
|
||||||
|
MIDDLE_SCHOOL = 'middle', _('Middle school')
|
||||||
|
HIGH_SCHOOL = 'high', _('High school')
|
||||||
|
ASSOCIATE_DEGREE = 'associate', _('Associate degree')
|
||||||
|
BACHELORS_DEGREE = 'bachelors', _('Bachelors degree')
|
||||||
|
MASTERS_DEGREE = 'masters', _('Masters degree')
|
||||||
|
DOCTORATE = 'doctorate', _('Doctorate')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
# Generated by Django 5.1.7 on 2025-05-15 12:31
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0004_alter_user_balance'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='birthdate',
|
||||||
|
field=models.DateField(blank=True, null=True, verbose_name='birthdate'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='education_degree',
|
||||||
|
field=models.CharField(blank=True, choices=[('primary', 'Primary school'), ('middle', 'Middle school'), ('high', 'High school'), ('associate', 'Associate degree'), ('bachelors', 'Bachelors degree'), ('masters', 'Masters degree'), ('doctorate', 'Doctorate')], max_length=10, null=True, verbose_name='education degree'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='education_field',
|
||||||
|
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='education field'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='gender',
|
||||||
|
field=models.CharField(blank=True, choices=[('m', 'male'), ('f', 'female')], null=True, verbose_name='gender'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -16,7 +16,7 @@ from utils.clients.payam_sms import send_sms
|
||||||
from .provinces_and_cities import state
|
from .provinces_and_cities import state
|
||||||
# from .tasks import send_notification
|
# from .tasks import send_notification
|
||||||
|
|
||||||
from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS
|
from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS, GenderChoices, EducationDegreeChoices
|
||||||
|
|
||||||
|
|
||||||
class UserManager(BaseUserManager):
|
class UserManager(BaseUserManager):
|
||||||
|
|
@ -124,6 +124,10 @@ class User(AbstractUser):
|
||||||
iban_verified = models.BooleanField(null=True)
|
iban_verified = models.BooleanField(null=True)
|
||||||
|
|
||||||
avatar = models.ImageField(upload_to='avatars', null=True, blank=True)
|
avatar = models.ImageField(upload_to='avatars', null=True, blank=True)
|
||||||
|
gender = models.CharField(_('gender'), choices=GenderChoices.choices, blank=True, null=True)
|
||||||
|
education_degree = models.CharField(_('education degree'), choices=EducationDegreeChoices.choices, max_length=10, null=True, blank=True)
|
||||||
|
education_field = models.CharField(_('education field'), max_length=100, null=True, blank=True)
|
||||||
|
birthdate = models.DateField(_('birthdate'), null=True, blank=True)
|
||||||
|
|
||||||
last_update = models.DateTimeField(_('last update'), max_length=30, blank=True, null=True, auto_now=True)
|
last_update = models.DateTimeField(_('last update'), max_length=30, blank=True, null=True, auto_now=True)
|
||||||
last_login = models.DateTimeField(_('last login'), blank=True, null=True)
|
last_login = models.DateTimeField(_('last login'), blank=True, null=True)
|
||||||
|
|
@ -143,17 +147,18 @@ class User(AbstractUser):
|
||||||
return state.get_province_by_id(self.province)
|
return state.get_province_by_id(self.province)
|
||||||
|
|
||||||
def set_otp(self):
|
def set_otp(self):
|
||||||
if settings.DEBUG or self.phone_number in DEVELOPMENT_PHONE_NUMBERS:
|
# if settings.DEBUG or self.phone_number in DEVELOPMENT_PHONE_NUMBERS:
|
||||||
self.otp = '12345'
|
# self.otp = '77501'
|
||||||
|
#
|
||||||
else:
|
# else:
|
||||||
self.otp = ''.join(random.choice('0123456789') for _ in range(5))
|
# self.otp = ''.join(random.choice('0123456789') for _ in range(5))
|
||||||
|
self.otp = ''.join(random.choice('0123456789') for _ in range(5))
|
||||||
|
|
||||||
self.otp_expire = timezone.now() + timedelta(minutes=5)
|
self.otp_expire = timezone.now() + timedelta(minutes=5)
|
||||||
self.otp_try = 0
|
self.otp_try = 0
|
||||||
|
|
||||||
def set_ott(self):
|
def set_ott(self):
|
||||||
self.ott = ''.join(random.choice(string.ascii_letters+string.digits) for _ in range(32))
|
self.ott = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(32))
|
||||||
# self.ott = ''.join(random.choice(string.ascii_letters+string.digits+string.punctuation) for _ in range(32))
|
# self.ott = ''.join(random.choice(string.ascii_letters+string.digits+string.punctuation) for _ in range(32))
|
||||||
self.ott_expire = timezone.now() + timedelta(seconds=300)
|
self.ott_expire = timezone.now() + timedelta(seconds=300)
|
||||||
|
|
||||||
|
|
@ -179,7 +184,7 @@ class User(AbstractUser):
|
||||||
self.save()
|
self.save()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def check_ott(self, ott:str):
|
def check_ott(self, ott: str):
|
||||||
ott = ott.strip()
|
ott = ott.strip()
|
||||||
if ott and self.ott == ott and self.ott_is_valid():
|
if ott and self.ott == ott and self.ott_is_valid():
|
||||||
self.ott = None
|
self.ott = None
|
||||||
|
|
@ -219,12 +224,13 @@ class User(AbstractUser):
|
||||||
send_sms(self.phone_number.strip('+'), message)
|
send_sms(self.phone_number.strip('+'), message)
|
||||||
return
|
return
|
||||||
# TODO: enable celery
|
# TODO: enable celery
|
||||||
send_notification(phone_number=self.phone_number,
|
send_notification(
|
||||||
title=title,
|
phone_number=self.phone_number,
|
||||||
body=body,
|
title=title,
|
||||||
user_uuid=self.uuid,
|
body=body,
|
||||||
notification_type=1,
|
user_uuid=self.uuid,
|
||||||
)
|
notification_type=1,
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name or self.get_full_name() or self.username or self.phone_number or self.email or _('no name')
|
return self.name or self.get_full_name() or self.username or self.phone_number or self.email or _('no name')
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ class AccountSerializer(serializers.ModelSerializer):
|
||||||
"last_name",
|
"last_name",
|
||||||
'name',
|
'name',
|
||||||
'avatar',
|
'avatar',
|
||||||
|
'gender',
|
||||||
|
'education_degree',
|
||||||
|
'education_field',
|
||||||
|
'birthdate',
|
||||||
'iban',
|
'iban',
|
||||||
'iban_verified',
|
'iban_verified',
|
||||||
# 'country',
|
# 'country',
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue