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:
Roberto Rosario
2017-07-24 16:32:30 -04:00
parent 76539f9eb0
commit 60cc0346fe
5 changed files with 35 additions and 18 deletions

View File

@@ -19,6 +19,7 @@ from navigation.classes import Separator, Text
from rest_api.classes import APIEndPoint
from .handlers import (
handler_pre_initial_setup, handler_pre_upgrade,
user_locale_profile_session_config, user_locale_profile_create
)
from .links import (
@@ -32,6 +33,7 @@ from .menus import menu_about, menu_main, menu_tools, menu_user
from .licenses import * # NOQA
from .queues import * # NOQA - Force queues registration
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
logger = logging.getLogger(__name__)
@@ -145,6 +147,15 @@ class CommonApp(MayanAppConfig):
dispatch_uid='user_locale_profile_create',
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_locale_profile_session_config,
dispatch_uid='user_locale_profile_session_config'

View File

@@ -2,9 +2,19 @@ from __future__ import unicode_literals
from django.apps import apps
from django.conf import settings
from django.core import management
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):
UserLocaleProfile = apps.get_model(
app_label='common', model_name='UserLocaleProfile'

View File

@@ -3,7 +3,7 @@ from __future__ import unicode_literals
from django.core import management
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):
@@ -11,17 +11,6 @@ class Command(management.BaseCommand):
def handle(self, *args, **options):
management.call_command('createsettings', interactive=False)
try:
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
pre_initial_setup.send(sender=self)
management.call_command('createautoadmin', interactive=False)
post_initial_setup.send(sender=self)

View File

@@ -3,28 +3,32 @@ from __future__ import unicode_literals
from django.core import management
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):
help = 'Performs the required steps after a version upgrade.'
def handle(self, *args, **options):
management.call_command('migrate', fake_initial=True, interactive=False)
management.call_command('purgeperiodictasks', interactive=False)
try:
pre_upgrade.send(sender=self)
except Exception as exception:
raise CommandError(
'Error during pre_upgrade signal: %s' % exception
)
try:
perform_upgrade.send(sender=self)
except Exception as exception:
raise CommandError(
'Error executing upgrade task; %s' % exception
'Error during perform_upgrade signal; %s' % exception
)
try:
post_upgrade.send(sender=self)
except Exception as exception:
raise CommandError(
'Error executing post-upgrade task; %s' % exception
'Error during post_upgrade signal; %s' % exception
)

View File

@@ -5,3 +5,6 @@ from django.dispatch import Signal
perform_upgrade = Signal(use_caching=True)
post_initial_setup = Signal(use_caching=True)
post_upgrade = Signal(use_caching=True)
pre_initial_setup = Signal(use_caching=True)
pre_upgrade = Signal(use_caching=True)