nice clean

This commit is contained in:
Louis Mazin 2026-09-21 14:46:44 +02:00
parent a84edb734a
commit 876ec75a4e

View File

@ -1,10 +1,7 @@
import sys
import logging
from django.apps import AppConfig
from django.core.management import execute_from_command_line
logger = logging.getLogger(__name__)
class UsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'users'
@ -31,10 +28,10 @@ class UsersConfig(AppConfig):
# Check if superuser already exists
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():
logger.info('A superuser already exists; no admin user was created.')
print('A superuser already exists; no admin user was created.')
return
username = config('ADMIN_USERNAME', default='').strip()
@ -43,7 +40,7 @@ class UsersConfig(AppConfig):
last_name = config('ADMIN_LAST_NAME', default='').strip()
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
with transaction.atomic():
@ -68,7 +65,7 @@ class UsersConfig(AppConfig):
user.save()
action = 'created' if created else 'synchronized'
logger.info(f'Admin user "{username}" {action}.')
print(f'Admin user "{username}" {action}.')
except Exception as e:
# Don't fail the entire Django startup if there's an error