@@ -0,0 +1,71 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from apps.profiles.models import SearchProfile
|
||||
from apps.profiles.services import save_profile_revision
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Maakt het eerste account, een standaardzoekprofiel en optionele demodata."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("--with-demo", action="store_true")
|
||||
parser.add_argument(
|
||||
"--username", default=os.getenv("VACATURERADAR_ADMIN_USERNAME", "admin")
|
||||
)
|
||||
parser.add_argument("--email", default=os.getenv("VACATURERADAR_ADMIN_EMAIL", ""))
|
||||
parser.add_argument("--password", default=os.getenv("VACATURERADAR_ADMIN_PASSWORD", ""))
|
||||
|
||||
def handle(self, *args, **options):
|
||||
User = get_user_model()
|
||||
username = options["username"]
|
||||
password = options["password"]
|
||||
user, created = User.objects.get_or_create(
|
||||
username=username,
|
||||
defaults={"email": options["email"], "is_staff": True, "is_superuser": True},
|
||||
)
|
||||
if created:
|
||||
if not password or password.startswith("CHANGE_ME"):
|
||||
raise CommandError("Stel VACATURERADAR_ADMIN_PASSWORD in of geef --password mee.")
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
self.stdout.write(self.style.SUCCESS(f"Beheerder {username} aangemaakt."))
|
||||
else:
|
||||
self.stdout.write(f"Beheerder {username} bestaat al.")
|
||||
|
||||
profile, profile_created = SearchProfile.objects.get_or_create(
|
||||
user=user,
|
||||
name="Primair IT-profiel",
|
||||
defaults={
|
||||
"is_active": True,
|
||||
"desired_titles": [
|
||||
"systeembeheerder",
|
||||
"system engineer",
|
||||
"infrastructure engineer",
|
||||
"workplace engineer",
|
||||
],
|
||||
"excluded_titles": ["sales", "recruiter"],
|
||||
"desired_skills": ["Microsoft 365", "Windows Server", "VMware", "netwerk"],
|
||||
"preferred_workplace": ["hybrid", "on_site"],
|
||||
},
|
||||
)
|
||||
if profile_created:
|
||||
save_profile_revision(profile, reason="bootstrap")
|
||||
self.stdout.write(self.style.SUCCESS("Standaardzoekprofiel aangemaakt."))
|
||||
|
||||
if options["with_demo"]:
|
||||
fixture = Path("fixtures/pages/sample_jsonld_job.html")
|
||||
if fixture.exists():
|
||||
call_command(
|
||||
"import_job_fixture",
|
||||
str(fixture),
|
||||
url="https://jobs.example.org/vacatures/infrastructure-engineer",
|
||||
source_name="Voorbeeldwerkgever",
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS("Demovacature geïmporteerd."))
|
||||
Reference in New Issue
Block a user