Skip to content
Snippets Groups Projects
Verified Commit 8ff87029 authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

feat: add initialize & loadfixtures management commands

parent e7496867
No related branches found
No related tags found
No related merge requests found
import os
from django.core.management import call_command
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = "Initializes the application."
def handle(self, *args, **options):
AURA_PROTO = os.getenv("AURA_PROTO")
AURA_HOST = os.getenv("AURA_HOST")
TANK_CALLBACK_BASE_URL = os.getenv(
"TANK_CALLBACK_BASE_URL",
default=f"{AURA_PROTO}://{AURA_HOST}/tank",
)
DASHBOARD_CALLBACK_BASE_URL = os.getenv(
"DASHBOARD_CALLBACK_BASE_URL",
default=f"{AURA_PROTO}://${AURA_HOST}",
)
call_command("migrate", "--no-input")
try:
call_command("createsuperuser", "--no-input")
except CommandError:
raise CommandError(f"The application is already initialized.")
call_command("collectstatic", "--no-input")
call_command(
"create_oidc_client",
"dashboard",
"public",
"--client-id",
os.getenv("DASHBOARD_OIDC_CLIENT_ID"),
"--client-secret",
os.getenv("DASHBOARD_OIDC_CLIENT_SECRET"),
"-r",
"id_token token",
"-u",
f"{DASHBOARD_CALLBACK_BASE_URL}/oidc_callback.html",
"-u",
f"{DASHBOARD_CALLBACK_BASE_URL}/oidc_callback_silentRenew.html",
"-p",
DASHBOARD_CALLBACK_BASE_URL,
)
call_command(
"create_oidc_client",
"tank",
"confidential",
"--client-id",
os.getenv("TANK_OIDC_CLIENT_ID"),
"--client-secret",
os.getenv("TANK_OIDC_CLIENT_SECRET"),
"-r",
"code",
"-u",
f"{TANK_CALLBACK_BASE_URL}/tank/auth/oidc/callback",
)
call_command("addpermissions")
call_command("creatersakey")
import glob
from django.core.management import BaseCommand, call_command
class Command(BaseCommand):
help = "Loads the fixtures from the directory."
def add_arguments(self, parser):
parser.add_argument("directory", help="Directory with fixtures.", nargs="+", type=str)
def handle(self, *args, **options):
directories = options["directory"]
for directory in directories:
if files := glob.glob(f"fixtures/{directory}/*.json"):
call_command("loaddata", files)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment