77 lines
3.5 KiB
Python
77 lines
3.5 KiB
Python
# Generated by Django 5.2.4 on 2025-08-26 05:22
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
def create_debug_superuser(apps,schema_editor):
|
|
from django.conf import settings
|
|
from user.models import UserProfile
|
|
from allauth.account.models import EmailAddress
|
|
|
|
if settings.DEBUG and UserProfile.objects.count() == 0:
|
|
user = UserProfile.objects.create_superuser("debug-admin","debug-admin@example.com","Pa55w.rd")
|
|
account_emailaddress = EmailAddress.objects.create(user=user,email=user.email,verified=True,primary=True)
|
|
|
|
def create_superuser(apps,schema_editor):
|
|
from django.conf import settings
|
|
from user.models import UserProfile
|
|
from allauth.account.models import EmailAddress
|
|
|
|
username = settings.ENV.str("SUPERUSER_USERNAME",default="")
|
|
email = settings.ENV.str("SUPERUSER_EMAIL",default="")
|
|
password = settings.ENV.str("SUPERUSER_PASSWORD",default="")
|
|
|
|
|
|
if username and email:
|
|
if not password:
|
|
password = None
|
|
user = UserProfile.objects.create_superuser(username,email,password)
|
|
account_emailaddress = EmailAddress.objects.create(user=user,email=user.email,verified=True,primary=True)
|
|
|
|
for i in range(0,100):
|
|
username = settings.ENV.str(f"SUPERUSER{i:d}_USERNAME",default="")
|
|
email = settings.ENV.str(f"SUPERUSER{i:d}_EMAIL",default="")
|
|
password = settings.ENV.str(f"SUPERUSER{i:d}_PASSWORD",default="")
|
|
if username and email:
|
|
if not password:
|
|
password = None
|
|
user = UserProfile.objects.create_superuser(username,email,password)
|
|
account_emailaddress = EmailAddress.objects.create(user=user,email=user.email,verified=True,primary=True)
|
|
|
|
def create_staffuser(apps,schema_editor):
|
|
from django.conf import settings
|
|
from user.models import UserProfile
|
|
from allauth.account.models import EmailAddress
|
|
|
|
username = settings.ENV.str("STAFFUSER_USERNAME",default="")
|
|
email = settings.ENV.str("STAFFUSER_EMAIL",default="")
|
|
password = settings.ENV.str("STAFFUSER_PASSWORD",default="")
|
|
|
|
|
|
if username and email:
|
|
if not password:
|
|
password = None
|
|
user = UserProfile.objects.create_user(username,email,password,is_staff=True)
|
|
account_emailaddress = EmailAddress.objects.create(user=user,email=user.email,verified=True,primary=True)
|
|
|
|
for i in range(0,100):
|
|
username = settings.ENV.str(f"STAFFUSER{i:d}_USERNAME",default="")
|
|
email = settings.ENV.str(f"STAFFUSER{i:d}_EMAIL",default="")
|
|
password = settings.ENV.str(f"STAFFUSER{i:d}_PASSWORD",default="")
|
|
if username and email:
|
|
if not password:
|
|
password = None
|
|
user = UserProfile.objects.create_user(username,email,password,is_staff=True)
|
|
account_emailaddress = EmailAddress.objects.create(user=user,email=user.email,verified=True,primary=True)
|
|
|
|
dependencies = [
|
|
('user', '0001_initial'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(create_superuser),
|
|
migrations.RunPython(create_debug_superuser),
|
|
]
|