mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow auto-loading of plugins in certain conditions (#3762)
Ref: 52af196694
This commit is contained in:
parent
67740581fe
commit
c146256170
@ -13,7 +13,7 @@ def isImportingData():
|
|||||||
return 'loaddata' in sys.argv
|
return 'loaddata' in sys.argv
|
||||||
|
|
||||||
|
|
||||||
def canAppAccessDatabase(allow_test=False):
|
def canAppAccessDatabase(allow_test: bool = False, allow_plugins: bool = False):
|
||||||
"""Returns True if the apps.py file can access database records.
|
"""Returns True if the apps.py file can access database records.
|
||||||
|
|
||||||
There are some circumstances where we don't want the ready function in apps.py
|
There are some circumstances where we don't want the ready function in apps.py
|
||||||
@ -25,8 +25,6 @@ def canAppAccessDatabase(allow_test=False):
|
|||||||
'flush',
|
'flush',
|
||||||
'loaddata',
|
'loaddata',
|
||||||
'dumpdata',
|
'dumpdata',
|
||||||
'makemigrations',
|
|
||||||
'migrate',
|
|
||||||
'check',
|
'check',
|
||||||
'shell',
|
'shell',
|
||||||
'createsuperuser',
|
'createsuperuser',
|
||||||
@ -43,6 +41,12 @@ def canAppAccessDatabase(allow_test=False):
|
|||||||
# Override for testing mode?
|
# Override for testing mode?
|
||||||
excluded_commands.append('test')
|
excluded_commands.append('test')
|
||||||
|
|
||||||
|
if not allow_plugins:
|
||||||
|
excluded_commands.extend([
|
||||||
|
'makemigrations',
|
||||||
|
'migrate',
|
||||||
|
])
|
||||||
|
|
||||||
for cmd in excluded_commands:
|
for cmd in excluded_commands:
|
||||||
if cmd in sys.argv:
|
if cmd in sys.argv:
|
||||||
return False
|
return False
|
||||||
|
@ -27,7 +27,7 @@ class PluginAppConfig(AppConfig):
|
|||||||
def ready(self):
|
def ready(self):
|
||||||
"""The ready method is extended to initialize plugins."""
|
"""The ready method is extended to initialize plugins."""
|
||||||
if settings.PLUGINS_ENABLED:
|
if settings.PLUGINS_ENABLED:
|
||||||
if not canAppAccessDatabase(allow_test=True):
|
if not canAppAccessDatabase(allow_test=True, allow_plugins=True):
|
||||||
logger.info("Skipping plugin loading sequence") # pragma: no cover
|
logger.info("Skipping plugin loading sequence") # pragma: no cover
|
||||||
else:
|
else:
|
||||||
logger.info('Loading InvenTree plugins')
|
logger.info('Loading InvenTree plugins')
|
||||||
|
Loading…
Reference in New Issue
Block a user