diff --git a/HISTORY.rst b/HISTORY.rst index 3c9034960e..40381abfd5 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -158,6 +158,7 @@ MAYAN_DATABASE_USER, MAYAN_DATABASE_PASSWORD, MAYAN_DATABASE_HOST, MAYAN_DATABASE_PORT, MAYAN_DEBUG. - Stricter defaults. CELERY_ALWAYS_EAGER to False, ALLOWED_HOSTS to ['127.0.0.1', 'localhost', '[::1]']. +- New initialization command. Creates media/system and populates the SECRET_KEY and VERSION files. 2.7.3 (2017-09-11) ================== diff --git a/docs/releases/3.0.rst b/docs/releases/3.0.rst index 413a072b0c..e7c227e49c 100644 --- a/docs/releases/3.0.rst +++ b/docs/releases/3.0.rst @@ -477,6 +477,7 @@ Other changes worth mentioning MAYAN_DATABASE_USER, MAYAN_DATABASE_PASSWORD, MAYAN_DATABASE_HOST, MAYAN_DATABASE_PORT, MAYAN_DEBUG. - Stricter defaults. CELERY_ALWAYS_EAGER to False, ALLOWED_HOSTS to ['127.0.0.1', 'localhost', '[::1]']. +- New initialization command. Creates media/system and populates the SECRET_KEY and VERSION files. Removals -------- diff --git a/mayan/apps/common/management/commands/initialsetup.py b/mayan/apps/common/management/commands/initialsetup.py index eadbe6c7cb..83afd65437 100644 --- a/mayan/apps/common/management/commands/initialsetup.py +++ b/mayan/apps/common/management/commands/initialsetup.py @@ -1,6 +1,13 @@ from __future__ import unicode_literals +import os + +from django.conf import settings from django.core import management +from django.core.management.utils import get_random_secret_key + +import mayan +from mayan.settings.literals import SECRET_KEY_FILENAME, SYSTEM_DIR from ...signals import post_initial_setup, pre_initial_setup @@ -8,8 +15,25 @@ from ...signals import post_initial_setup, pre_initial_setup class Command(management.BaseCommand): help = 'Initializes an install and gets it ready to be used.' + def initialize_system(self): + system_path = os.path.join(settings.MEDIA_ROOT, SYSTEM_DIR) + secret_key_file_path = os.path.join(system_path, SECRET_KEY_FILENAME) + + if not os.path.exists(system_path): + os.makedirs(system_path) + + version_file_path = os.path.join(system_path, 'VERSION') + with open(version_file_path, 'w+') as file_object: + file_object.write(mayan.__version__) + + with open(secret_key_file_path, 'w+') as file_object: + secret_key = get_random_secret_key() + file_object.write(secret_key) + + settings.SECRET_KEY = secret_key + def handle(self, *args, **options): - management.call_command('createsettings', interactive=False) + self.initialize_system() pre_initial_setup.send(sender=self) management.call_command('installjavascript', interactive=False) management.call_command('createautoadmin', interactive=False)