django-orchestra/orchestra/contrib/systemusers/apps.py

31 lines
1.3 KiB
Python
Raw Permalink Normal View History

2015-05-04 14:19:58 +00:00
import sys
2015-04-29 13:55:22 +00:00
from django.apps import AppConfig
2015-05-04 14:19:58 +00:00
from django.db.models.signals import post_migrate
from django.utils.translation import gettext_lazy as _
2015-05-04 14:19:58 +00:00
from orchestra.core import services
2015-04-29 13:55:22 +00:00
class SystemUsersConfig(AppConfig):
name = 'orchestra.contrib.systemusers'
verbose_name = "System users"
2015-05-04 14:19:58 +00:00
def ready(self):
from .models import SystemUser, WebappUsers
services.register(SystemUser, icon='roleplaying.png')
2015-05-04 14:19:58 +00:00
if 'migrate' in sys.argv and 'accounts' not in sys.argv:
post_migrate.connect(self.create_initial_systemuser,
dispatch_uid="orchestra.contrib.systemusers.apps.create_initial_systemuser")
services.register(WebappUsers, icon='roleplaying.png', verbose_name =_('WebApp User'), verbose_name_plural=_("Webapp users"))
2015-05-04 14:19:58 +00:00
def create_initial_systemuser(self, **kwargs):
from .models import SystemUser
2016-10-11 10:01:56 +00:00
Account = SystemUser.account.field.remote_field.model
2015-05-04 14:19:58 +00:00
for account in Account.objects.filter(is_superuser=True, main_systemuser_id__isnull=True):
systemuser = SystemUser.objects.create(username=account.username,
password=account.password, account=account)
account.main_systemuser = systemuser
account.save()
sys.stdout.write("Created initial systemuser %s.\n" % systemuser.username)