Merge branch 'aureplop/yolo/fix-setup-kfet-generic-user' into 'yolo'

Fix setup of the kfet generic user when…

See merge request !268
This commit is contained in:
Martin Pepin 2017-10-26 17:14:59 +02:00
commit dff19199ec
2 changed files with 20 additions and 3 deletions

View file

@ -10,5 +10,22 @@ class KFetAuthConfig(AppConfig):
def ready(self):
from . import signals # noqa
from .utils import setup_kfet_generic_user
post_migrate.connect(setup_kfet_generic_user, sender=self)
post_migrate.connect(finish_setup_kfet_generic_user, sender=self)
def finish_setup_kfet_generic_user(sender, apps, **kwargs):
from kfet.models import Account
from .utils import setup_kfet_generic_user
# Even if no kfetauth migration has been applied, the post_migrate signal
# is issued for KFetAuthConfig.
# Before finishing setup of the kfet generic user, check dependencies are
# ready: kfet.Account model and gestion.Profile (old schema may not use
# this model).
try:
apps.get_model('kfet', 'Account')
apps.get_model('gestion', 'Profile')
Account.objects.get_generic()
except (LookupError, Account.DoesNotExist):
return
setup_kfet_generic_user()

View file

@ -15,7 +15,7 @@ def get_kfet_generic_user():
return Account.objects.get_generic().user
def setup_kfet_generic_user(**kwargs):
def setup_kfet_generic_user():
"""
First steps of setup of the kfet generic user are done in a migration, as
it is more robust against database schema changes.