diff --git a/src/fellchensammlung/apps.py b/src/fellchensammlung/apps.py index 8e5ddd0..5c1f8b3 100644 --- a/src/fellchensammlung/apps.py +++ b/src/fellchensammlung/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from .tools.signals import ensure_groups +from .tools.signals import ensure_groups, ensure_languages from django.db.models.signals import post_migrate @@ -14,3 +14,4 @@ class FellchensammlungConfig(AppConfig): post_migrate.connect(ensure_groups, sender=self) except Permission.DoesNotExist: pass + post_migrate.connect(ensure_languages, sender=self) diff --git a/src/fellchensammlung/tools/signals.py b/src/fellchensammlung/tools/signals.py index 6cc16ab..8dd6005 100644 --- a/src/fellchensammlung/tools/signals.py +++ b/src/fellchensammlung/tools/signals.py @@ -1,20 +1,21 @@ +import logging + + def _get_perms(permission_name_list): from django.contrib.auth.models import Permission permissions = [] for permission_name in permission_name_list: - print(f"{permission_name}") try: permission = Permission.objects.get(codename=permission_name) permissions.append(permission) except Permission.DoesNotExist: - print("aaaaaa") + logging.warning("Permissions not correctly migrated, please run the migration again") return permissions def ensure_groups(sender, **kwargs): from django.contrib.auth.models import Group from django.contrib.auth.models import Permission - print([permission.name for permission in Permission.objects.all()]) member_permissions = [] @@ -33,3 +34,8 @@ def ensure_groups(sender, **kwargs): members, created = Group.objects.get_or_create(name="Members") members.permissions.set(_get_perms(member_permissions)) + +def ensure_languages(sender, **kwargs): + from fellchensammlung.models import Language + Language.objects.get_or_create(name="Deutsch", languagecode="de") + Language.objects.get_or_create(name="English", languagecode="en")