nice clean
This commit is contained in:
parent
a84edb734a
commit
876ec75a4e
@ -1,10 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import logging
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class UsersConfig(AppConfig):
|
class UsersConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'users'
|
name = 'users'
|
||||||
@ -31,10 +28,10 @@ class UsersConfig(AppConfig):
|
|||||||
|
|
||||||
# Check if superuser already exists
|
# Check if superuser already exists
|
||||||
existing_superusers = User.objects.filter(is_superuser=True)
|
existing_superusers = User.objects.filter(is_superuser=True)
|
||||||
logger.info(f"Found {existing_superusers.count()} existing superusers")
|
print(f"Found {existing_superusers.count()} existing superusers")
|
||||||
|
|
||||||
if existing_superusers.exists():
|
if existing_superusers.exists():
|
||||||
logger.info('A superuser already exists; no admin user was created.')
|
print('A superuser already exists; no admin user was created.')
|
||||||
return
|
return
|
||||||
|
|
||||||
username = config('ADMIN_USERNAME', default='').strip()
|
username = config('ADMIN_USERNAME', default='').strip()
|
||||||
@ -43,7 +40,7 @@ class UsersConfig(AppConfig):
|
|||||||
last_name = config('ADMIN_LAST_NAME', default='').strip()
|
last_name = config('ADMIN_LAST_NAME', default='').strip()
|
||||||
|
|
||||||
if not username or not password:
|
if not username or not password:
|
||||||
logger.info('ADMIN_USERNAME and ADMIN_PASSWORD are required; no admin was created.')
|
print('ADMIN_USERNAME and ADMIN_PASSWORD are required; no admin was created.')
|
||||||
return
|
return
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
@ -68,7 +65,7 @@ class UsersConfig(AppConfig):
|
|||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
action = 'created' if created else 'synchronized'
|
action = 'created' if created else 'synchronized'
|
||||||
logger.info(f'Admin user "{username}" {action}.')
|
print(f'Admin user "{username}" {action}.')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Don't fail the entire Django startup if there's an error
|
# Don't fail the entire Django startup if there's an error
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user