web_framework: Split initialization into two parts

A simple Django configuration does not need to create the database whereas DB
migration requires creating the database.

In some operations such as listing dependencies, we can skip running the second
part and so writing to database will no longer be necessary during such
operations.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2020-06-24 14:35:45 -07:00 committed by James Valleroy
parent 91c4d6742e
commit 28fe8c8c3e
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 4 additions and 0 deletions

View File

@ -132,6 +132,7 @@ def main():
log.init()
web_framework.init()
web_framework.post_init()
logger.info('FreedomBox Service (Plinth) version - %s', __version__)
for config_file in cfg.config_files:

View File

@ -53,6 +53,9 @@ def init():
logger.debug('Configured Django with applications - %s',
settings.INSTALLED_APPS)
def post_init():
"""Perform operations after completing init of other modules."""
logger.debug('Creating or adding new tables to data file')
django.core.management.call_command('migrate', '--fake-initial',
interactive=False, verbosity=0)