from django.core.management.base import BaseCommand
from memopolis.models import User, Organization, Team, Map, Quest, SiteConfiguration
[docs]
def get_or_create_user(username, is_superuser=False):
user, created = User.objects.get_or_create(username=username, is_superuser=is_superuser, is_staff=is_superuser)
if created:
user.set_password('insecure')
user.save()
return user
[docs]
class Command(BaseCommand):
help = 'Check Memopolis configuration.'
[docs]
def handle(self, *args, **options):
self.stdout.write(self.style.MIGRATE_LABEL("\nCreating initial users and teams..."))
self.stdout.write("creating superadmin user: superuser")
superuser = get_or_create_user('admin', True)
self.stdout.write("creating organization: demo-org1")
org, created = Organization.objects.get_or_create(name="demo-org1")
self.stdout.write("creating organization: demo-org2")
org2, created = Organization.objects.get_or_create(name="demo-org2")
self.stdout.write("creating teams: admin-team, demo-team, demo-team2")
admin_team, created = Team.objects.get_or_create(name="admin-team", organization=org)
team1, created = Team.objects.get_or_create(name="demo-team", organization=org)
team2, created = Team.objects.get_or_create(name="demo-team2", organization=org)
superuser.teams.add(admin_team)
superuser.active_team = admin_team
superuser.organization = org
superuser.save()
self.stdout.write("creating admin user of team demo-team: demo-admin")
org_admin = get_or_create_user('demo-admin')
org_admin.organization = org
org_admin.active_team = team1
org_admin.save()
if not org_admin in org.admins.all():
org.admins.add(org_admin)
self.stdout.write("creating member user of teams demo-team1+demo-team2: demo-team-member")
team_member = get_or_create_user('demo-team-member')
team_member.organization = org
team_member.active_team = team1
team_member.teams.add(team1, team2)
team_member.save()
self.stdout.write("creating quest: Default Quest")
lobby_quest, created = Quest.objects.get_or_create(name="Default Quest", organization=org, team=admin_team)
self.stdout.write("creating map: Home Map\n")
home_map, created = Map.objects.get_or_create(name="Home Map", quest=lobby_quest)
site_config = SiteConfiguration.get_solo()
site_config.home_map = home_map
site_config.save()