Merge pull request #10 from jedie/fix-init

Bugfix init: move Database access from checks into post-migate signal
pull/11/head
Jens Diemer 2020-10-25 16:34:28 +01:00 zatwierdzone przez GitHub
commit bc761d3624
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 28 dodań i 28 usunięć

Wyświetl plik

@ -16,3 +16,4 @@ class InventoryConfig(AppConfig):
def ready(self):
import inventory.checks # noqa
import inventory.signals # noqa

Wyświetl plik

@ -1,8 +1,6 @@
from pathlib import Path
from django.core.checks import Error, Warning, register
from inventory.permissions import get_or_create_normal_user_group, setup_normal_user_permissions
from django.core.checks import Error, register
@register()
@ -17,25 +15,3 @@ def inventory_checks(app_configs, **kwargs):
)
)
return errors
@register()
def inventory_user_groups(app_configs, **kwargs):
"""
Setup PyInventory user groups
"""
warnings = []
normal_user_group, created = get_or_create_normal_user_group()
if created:
warnings.append(
Warning(f'User group {normal_user_group} created')
)
updated = setup_normal_user_permissions(normal_user_group)
if updated:
warnings.append(
Warning(f'Update permissions for {normal_user_group}')
)
return warnings

Wyświetl plik

@ -0,0 +1,15 @@
from django.db.models.signals import post_migrate
from django.dispatch import receiver
from inventory.permissions import get_or_create_normal_user_group, setup_normal_user_permissions
@receiver(post_migrate)
def post_migrate_callback(sender, **kwargs):
normal_user_group, created = get_or_create_normal_user_group()
if created:
print(f'User group {normal_user_group} created')
updated = setup_normal_user_permissions(normal_user_group)
if updated:
print(f'Update permissions for {normal_user_group}')

Wyświetl plik

@ -11,4 +11,4 @@ from inventory import __version__
if __name__ == 'inventory_project':
if '--version' not in sys.argv:
print(f'PyInventory v{__version__} (Django v{django_version})')
print(f'PyInventory v{__version__} (Django v{django_version})', file=sys.stderr)

Wyświetl plik

@ -4,12 +4,13 @@
import logging
import os as __os
import sys as __sys
from pathlib import Path as __Path
from django.utils.translation import ugettext_lazy as _
print('Use settings:', __file__)
print(f'Use settings: {__file__!r}', file=__sys.stderr)
# Build paths inside the project:
@ -117,7 +118,7 @@ else:
'timeout': 30,
}
}
print(f'Use Database: {DATABASES["default"]["NAME"]!r}')
print(f'Use Database: {DATABASES["default"]["NAME"]!r}', file=__sys.stderr)
# _____________________________________________________________________________
# Internationalization
@ -216,6 +217,13 @@ TAGULOUS_LABEL_MAX_LENGTH = TAGULOUS_NAME_MAX_LENGTH
TAGULOUS_SLUG_TRUNCATE_UNIQUE = 5
TAGULOUS_SLUG_ALLOW_UNICODE = False
SERIALIZATION_MODULES = {
'xml': 'tagulous.serializers.xml_serializer',
'json': 'tagulous.serializers.json',
'python': 'tagulous.serializers.python',
'yaml': 'tagulous.serializers.pyyaml',
}
# _____________________________________________________________________________
# cut 'pathname' in log output