fix models.py issue
This commit is contained in:
150
rog/models.py
150
rog/models.py
@ -39,7 +39,7 @@ import uuid
|
||||
env = environ.Env(DEBUG=(bool, False))
|
||||
environ.Env.read_env(env_file=".env")
|
||||
|
||||
db = Db(dbname=env("POSTGRES_DBNAME"), user=env("POSTGRES_USER"), password=env("POSTGRES_PASS"), host="postgres-db", port=env("PG_PORT"))
|
||||
db = Db(dbname=env("POSTGRES_DBNAME"), user=env("POSTGRES_USER"), password=env("POSTGRES_PASS"), host=env("PG_HOST"), port=env("PG_PORT"))
|
||||
|
||||
|
||||
def get_file_path(instance, filename):
|
||||
@ -68,6 +68,80 @@ def remove_bom_inplace(path):
|
||||
fp.truncate()
|
||||
|
||||
#========== Akira ここから
|
||||
class CustomUserManager(BaseUserManager):
|
||||
|
||||
def create_user(self, email, password, group, event_code, team_name, **other_fields):
|
||||
if not email:
|
||||
raise ValueError(_("You must provide an email address"))
|
||||
|
||||
# ユニークなuseridを生成
|
||||
userid = str(uuid.uuid4())
|
||||
|
||||
user = self.model(
|
||||
email=self.normalize_email(email),
|
||||
firstname=firstname,
|
||||
lastname=lastname,
|
||||
userid=userid,
|
||||
date_of_birth=date_of_birth,
|
||||
)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
|
||||
return user
|
||||
|
||||
def create_superuser(self, email, password, group, event_code=None, team_name=None, **other_fields):
|
||||
user = self.create_user(
|
||||
email,
|
||||
firstname=firstname,
|
||||
lastname=lastname,
|
||||
date_of_birth=date_of_birth,
|
||||
password=password,
|
||||
)
|
||||
user.is_staff = True
|
||||
user.is_superuser = True
|
||||
user.is_active = True
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
|
||||
'''
|
||||
# Providing default values for event_code and team_name if they are not provided
|
||||
if event_code is None:
|
||||
event_code = 'test' # replace this with some default value
|
||||
if team_name is None:
|
||||
team_name = 'test' # replace this with some default value
|
||||
|
||||
other_fields.setdefault('is_staff', True)
|
||||
other_fields.setdefault('is_superuser', True)
|
||||
other_fields.setdefault('is_active', True)
|
||||
|
||||
if other_fields.get('is_staff') is not True:
|
||||
raise ValueError(_('Superuser must be assigned to staff'))
|
||||
if other_fields.get('is_superuser') is not True:
|
||||
raise ValueError(_('Superuser must have is_superuser set to True'))
|
||||
|
||||
return self.create_user(email, password, group, event_code, team_name, **other_fields)
|
||||
'''
|
||||
|
||||
class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||
email = models.EmailField(unique=True)
|
||||
firstname = models.CharField(max_length=255)
|
||||
lastname = models.CharField(max_length=255)
|
||||
userid = models.CharField(max_length=255, unique=True)
|
||||
date_of_birth = models.DateField()
|
||||
is_active = models.BooleanField(default=True)
|
||||
is_staff = models.BooleanField(default=False)
|
||||
event_code = models.CharField(max_length=255, blank=True, null=True)
|
||||
team_name = models.CharField(max_length=255, blank=True, null=True)
|
||||
zekken_number = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
||||
objects = CustomUserManager()
|
||||
|
||||
USERNAME_FIELD = 'email'
|
||||
REQUIRED_FIELDS = ['firstname', 'lastname', 'userid', 'date_of_birth']
|
||||
|
||||
def __str__(self):
|
||||
return self.email
|
||||
|
||||
class TempUser(models.Model):
|
||||
email = models.EmailField(unique=True)
|
||||
@ -132,80 +206,6 @@ class Entry(models.Model):
|
||||
#============= Akira ここまで
|
||||
|
||||
|
||||
class CustomUserManager(BaseUserManager):
|
||||
|
||||
def create_user(self, email, password, group, event_code, team_name, **other_fields):
|
||||
if not email:
|
||||
raise ValueError(_("You must provide an email address"))
|
||||
|
||||
# ユニークなuseridを生成
|
||||
userid = str(uuid.uuid4())
|
||||
|
||||
user = self.model(
|
||||
email=self.normalize_email(email),
|
||||
firstname=firstname,
|
||||
lastname=lastname,
|
||||
userid=userid,
|
||||
date_of_birth=date_of_birth,
|
||||
)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
|
||||
return user
|
||||
|
||||
def create_superuser(self, email, password, group, event_code=None, team_name=None, **other_fields):
|
||||
user = self.create_user(
|
||||
email,
|
||||
firstname=firstname,
|
||||
lastname=lastname,
|
||||
date_of_birth=date_of_birth,
|
||||
password=password,
|
||||
)
|
||||
user.is_staff = True
|
||||
user.is_superuser = True
|
||||
user.is_active = True
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
|
||||
/*
|
||||
# Providing default values for event_code and team_name if they are not provided
|
||||
if event_code is None:
|
||||
event_code = 'test' # replace this with some default value
|
||||
if team_name is None:
|
||||
team_name = 'test' # replace this with some default value
|
||||
|
||||
other_fields.setdefault('is_staff', True)
|
||||
other_fields.setdefault('is_superuser', True)
|
||||
other_fields.setdefault('is_active', True)
|
||||
|
||||
if other_fields.get('is_staff') is not True:
|
||||
raise ValueError(_('Superuser must be assigned to staff'))
|
||||
if other_fields.get('is_superuser') is not True:
|
||||
raise ValueError(_('Superuser must have is_superuser set to True'))
|
||||
|
||||
return self.create_user(email, password, group, event_code, team_name, **other_fields)
|
||||
*/
|
||||
|
||||
class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||
email = models.EmailField(unique=True)
|
||||
firstname = models.CharField(max_length=255)
|
||||
lastname = models.CharField(max_length=255)
|
||||
userid = models.CharField(max_length=255, unique=True)
|
||||
date_of_birth = models.DateField()
|
||||
is_active = models.BooleanField(default=True)
|
||||
is_staff = models.BooleanField(default=False)
|
||||
event_code = models.CharField(max_length=255, blank=True, null=True)
|
||||
team_name = models.CharField(max_length=255, blank=True, null=True)
|
||||
zekken_number = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
||||
objects = CustomUserManager()
|
||||
|
||||
USERNAME_FIELD = 'email'
|
||||
REQUIRED_FIELDS = ['firstname', 'lastname', 'userid', 'date_of_birth']
|
||||
|
||||
def __str__(self):
|
||||
return self.email
|
||||
|
||||
class JpnAdminMainPerf(models.Model):
|
||||
geom = models.MultiPolygonField(blank=True, null=True)
|
||||
|
||||
Reference in New Issue
Block a user