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 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
|
2015-05-07 14:09:37 +00:00
|
|
|
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")
|
|
|
|
|
|
|
|
def create_initial_systemuser(self, **kwargs):
|
|
|
|
from .models import SystemUser
|
|
|
|
Account = SystemUser.account.field.related.model
|
|
|
|
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)
|