Make the intialsetup and performupgrade management tasks
work with signals to allow customization from 3rd party apps. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ from navigation.classes import Separator, Text
|
|||||||
from rest_api.classes import APIEndPoint
|
from rest_api.classes import APIEndPoint
|
||||||
|
|
||||||
from .handlers import (
|
from .handlers import (
|
||||||
|
handler_pre_initial_setup, handler_pre_upgrade,
|
||||||
user_locale_profile_session_config, user_locale_profile_create
|
user_locale_profile_session_config, user_locale_profile_create
|
||||||
)
|
)
|
||||||
from .links import (
|
from .links import (
|
||||||
@@ -32,6 +33,7 @@ from .menus import menu_about, menu_main, menu_tools, menu_user
|
|||||||
from .licenses import * # NOQA
|
from .licenses import * # NOQA
|
||||||
from .queues import * # NOQA - Force queues registration
|
from .queues import * # NOQA - Force queues registration
|
||||||
from .settings import setting_auto_logging, setting_production_error_log_path
|
from .settings import setting_auto_logging, setting_production_error_log_path
|
||||||
|
from .signals import pre_initial_setup, pre_upgrade
|
||||||
from .tasks import task_delete_stale_uploads # NOQA - Force task registration
|
from .tasks import task_delete_stale_uploads # NOQA - Force task registration
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -145,6 +147,15 @@ class CommonApp(MayanAppConfig):
|
|||||||
dispatch_uid='user_locale_profile_create',
|
dispatch_uid='user_locale_profile_create',
|
||||||
sender=settings.AUTH_USER_MODEL
|
sender=settings.AUTH_USER_MODEL
|
||||||
)
|
)
|
||||||
|
pre_initial_setup.connect(
|
||||||
|
handler_pre_initial_setup,
|
||||||
|
dispatch_uid='common_handler_pre_initial_setup'
|
||||||
|
)
|
||||||
|
pre_upgrade.connect(
|
||||||
|
handler_pre_upgrade,
|
||||||
|
dispatch_uid='common_handler_pre_upgrade',
|
||||||
|
)
|
||||||
|
|
||||||
user_logged_in.connect(
|
user_logged_in.connect(
|
||||||
user_locale_profile_session_config,
|
user_locale_profile_session_config,
|
||||||
dispatch_uid='user_locale_profile_session_config'
|
dispatch_uid='user_locale_profile_session_config'
|
||||||
|
|||||||
@@ -2,9 +2,19 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core import management
|
||||||
from django.utils import timezone, translation
|
from django.utils import timezone, translation
|
||||||
|
|
||||||
|
|
||||||
|
def handler_pre_initial_setup(sender, **kwargs):
|
||||||
|
management.call_command('migrate', interactive=False)
|
||||||
|
|
||||||
|
|
||||||
|
def handler_pre_upgrade(sender, **kwargs):
|
||||||
|
management.call_command('migrate', fake_initial=True, interactive=False)
|
||||||
|
management.call_command('purgeperiodictasks', interactive=False)
|
||||||
|
|
||||||
|
|
||||||
def user_locale_profile_session_config(sender, request, user, **kwargs):
|
def user_locale_profile_session_config(sender, request, user, **kwargs):
|
||||||
UserLocaleProfile = apps.get_model(
|
UserLocaleProfile = apps.get_model(
|
||||||
app_label='common', model_name='UserLocaleProfile'
|
app_label='common', model_name='UserLocaleProfile'
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||||||
from django.core import management
|
from django.core import management
|
||||||
from django.db.utils import OperationalError
|
from django.db.utils import OperationalError
|
||||||
|
|
||||||
from ...signals import post_initial_setup
|
from ...signals import post_initial_setup, pre_initial_setup
|
||||||
|
|
||||||
|
|
||||||
class Command(management.BaseCommand):
|
class Command(management.BaseCommand):
|
||||||
@@ -11,17 +11,6 @@ class Command(management.BaseCommand):
|
|||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
management.call_command('createsettings', interactive=False)
|
management.call_command('createsettings', interactive=False)
|
||||||
try:
|
pre_initial_setup.send(sender=self)
|
||||||
management.call_command('migrate', interactive=False)
|
|
||||||
except OperationalError:
|
|
||||||
self.stderr.write(
|
|
||||||
self.style.NOTICE(
|
|
||||||
'Unable to migrate the database. The initialsetup '
|
|
||||||
'command is to be used only on new installations. To '
|
|
||||||
'upgrade existing installations use the performupgrade '
|
|
||||||
'command.'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
raise
|
|
||||||
management.call_command('createautoadmin', interactive=False)
|
management.call_command('createautoadmin', interactive=False)
|
||||||
post_initial_setup.send(sender=self)
|
post_initial_setup.send(sender=self)
|
||||||
|
|||||||
@@ -3,28 +3,32 @@ from __future__ import unicode_literals
|
|||||||
from django.core import management
|
from django.core import management
|
||||||
from django.core.management.base import CommandError
|
from django.core.management.base import CommandError
|
||||||
|
|
||||||
from ...signals import perform_upgrade, post_upgrade
|
from ...signals import perform_upgrade, post_upgrade, pre_upgrade
|
||||||
|
|
||||||
|
|
||||||
class Command(management.BaseCommand):
|
class Command(management.BaseCommand):
|
||||||
help = 'Performs the required steps after a version upgrade.'
|
help = 'Performs the required steps after a version upgrade.'
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
management.call_command('migrate', fake_initial=True, interactive=False)
|
try:
|
||||||
management.call_command('purgeperiodictasks', interactive=False)
|
pre_upgrade.send(sender=self)
|
||||||
|
except Exception as exception:
|
||||||
|
raise CommandError(
|
||||||
|
'Error during pre_upgrade signal: %s' % exception
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
perform_upgrade.send(sender=self)
|
perform_upgrade.send(sender=self)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
'Error executing upgrade task; %s' % exception
|
'Error during perform_upgrade signal; %s' % exception
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
post_upgrade.send(sender=self)
|
post_upgrade.send(sender=self)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
'Error executing post-upgrade task; %s' % exception
|
'Error during post_upgrade signal; %s' % exception
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,3 +5,6 @@ from django.dispatch import Signal
|
|||||||
perform_upgrade = Signal(use_caching=True)
|
perform_upgrade = Signal(use_caching=True)
|
||||||
post_initial_setup = Signal(use_caching=True)
|
post_initial_setup = Signal(use_caching=True)
|
||||||
post_upgrade = Signal(use_caching=True)
|
post_upgrade = Signal(use_caching=True)
|
||||||
|
pre_initial_setup = Signal(use_caching=True)
|
||||||
|
pre_upgrade = Signal(use_caching=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user