Update
This commit is contained in:
@@ -1,17 +1,13 @@
|
||||
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):
|
||||
help="Import seed CSV (idempotent)"
|
||||
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)
|
||||
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,28 +1,16 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import User
|
||||
import os
|
||||
|
||||
class Command(BaseCommand):
|
||||
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
|
||||
u.set_password(admin_pass)
|
||||
u.save()
|
||||
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
|
||||
u.set_password(editor_pass)
|
||||
u.save()
|
||||
self.stdout.write(self.style.SUCCESS(f"Editor user ensured: {editor_user}"))
|
||||
help="Ensure initial users from env"
|
||||
def handle(self,*args,**kwargs):
|
||||
au=os.getenv("ADMIN_USERNAME"); ap=os.getenv("ADMIN_PASSWORD")
|
||||
eu=os.getenv("USER_USERNAME"); ep=os.getenv("USER_PASSWORD")
|
||||
if au and ap:
|
||||
u,_=User.objects.get_or_create(username=au)
|
||||
u.is_staff=True; u.is_superuser=True; u.set_password(ap); u.save()
|
||||
self.stdout.write(self.style.SUCCESS(f"Admin ensured: {au}"))
|
||||
if eu and ep:
|
||||
u,_=User.objects.get_or_create(username=eu)
|
||||
u.is_staff=False; u.is_superuser=False; u.set_password(ep); u.save()
|
||||
self.stdout.write(self.style.SUCCESS(f"Editor ensured: {eu}"))
|
||||
|
||||
Reference in New Issue
Block a user