Update
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from pathlib import Path
|
||||
from core.utils import import_csv_bytes
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Import seed CSV (idempotent upsert by Code)."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("path", nargs="?", default="/data/imports/illustrations_seed.csv")
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
|
||||
def handle(self, path, dry_run, *args, **kwargs):
|
||||
p = Path(path)
|
||||
if not p.exists():
|
||||
raise CommandError(f"CSV not found: {p}")
|
||||
report = import_csv_bytes(p.read_bytes(), dry_run=dry_run)
|
||||
self.stdout.write(self.style.SUCCESS(str(report)))
|
||||
@@ -1,27 +1,28 @@
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import User
|
||||
import os
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **kwargs):
|
||||
admin_user = os.getenv("INIT_ADMIN_USERNAME")
|
||||
admin_pass = os.getenv("INIT_ADMIN_PASSWORD")
|
||||
editor_user = os.getenv("INIT_EDITOR_USERNAME")
|
||||
editor_pass = os.getenv("INIT_EDITOR_PASSWORD")
|
||||
help = "Create or update initial users from environment variables."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
admin_user = os.getenv("ADMIN_USERNAME")
|
||||
admin_pass = os.getenv("ADMIN_PASSWORD")
|
||||
editor_user = os.getenv("USER_USERNAME")
|
||||
editor_pass = os.getenv("USER_PASSWORD")
|
||||
|
||||
if admin_user and admin_pass:
|
||||
u, created = User.objects.get_or_create(username=admin_user)
|
||||
u.is_staff = True
|
||||
u.is_superuser = True
|
||||
if admin_pass:
|
||||
u.set_password(admin_pass)
|
||||
u.set_password(admin_pass)
|
||||
u.save()
|
||||
self.stdout.write(self.style.SUCCESS(f"Admin ready: {admin_user}"))
|
||||
self.stdout.write(self.style.SUCCESS(f"Admin user ensured: {admin_user}"))
|
||||
|
||||
if editor_user and editor_pass:
|
||||
u, created = User.objects.get_or_create(username=editor_user)
|
||||
u.is_staff = False
|
||||
u.is_superuser = False
|
||||
if editor_pass:
|
||||
u.set_password(editor_pass)
|
||||
u.set_password(editor_pass)
|
||||
u.save()
|
||||
self.stdout.write(self.style.SUCCESS(f"Editor ready: {editor_user}"))
|
||||
self.stdout.write(self.style.SUCCESS(f"Editor user ensured: {editor_user}"))
|
||||
|
||||
Reference in New Issue
Block a user