mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
* Revert "Remove stat context variables" This reverts commit 0989c308d0cea9b9405a1338d257b542c6d33d73. * Add a caching framework for inventree settings - Actions that use "settings" require a DB hit every time - For example the part.full_name() method looks at the PART_NAME_FORMAT setting - This means 1 DB hit for every part which is serialized!! * Fixes for DebugToolbar integration - Requires different INTERNAL_IPS when running behind docker - Some issues with TEMPLATES framework * Revert "Revert "Remove stat context variables"" This reverts commit 52e6359265226126da7ed6ed2aed2b83aa33de17. * Add unit tests for settings caching * Update existing unit tests to handle cache framework * Fix for unit test * Re-enable cache for default part values * Clear cache for further unit tests
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
"""Apps file for plugin app.
|
|
|
|
This initializes the plugin mechanisms and handles reloading throught the lifecycle.
|
|
The main code for plugin special sauce is in the plugin registry in `InvenTree/plugin/registry.py`.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from django.apps import AppConfig
|
|
from django.conf import settings
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from maintenance_mode.core import set_maintenance_mode
|
|
|
|
from InvenTree.ready import canAppAccessDatabase
|
|
from plugin import registry
|
|
from plugin.helpers import check_git_version, log_error
|
|
|
|
logger = logging.getLogger('inventree')
|
|
|
|
|
|
class PluginAppConfig(AppConfig):
|
|
"""AppConfig for plugins."""
|
|
|
|
name = 'plugin'
|
|
|
|
def ready(self):
|
|
"""The ready method is extended to initialize plugins."""
|
|
if settings.PLUGINS_ENABLED:
|
|
if not canAppAccessDatabase(allow_test=True):
|
|
logger.info("Skipping plugin loading sequence") # pragma: no cover
|
|
else:
|
|
logger.info('Loading InvenTree plugins')
|
|
|
|
if not registry.is_loading:
|
|
# this is the first startup
|
|
try:
|
|
from common.models import InvenTreeSetting
|
|
if InvenTreeSetting.get_setting('PLUGIN_ON_STARTUP', create=False, cache=False):
|
|
# make sure all plugins are installed
|
|
registry.install_plugin_file()
|
|
except Exception: # pragma: no cover
|
|
pass
|
|
|
|
# get plugins and init them
|
|
registry.collect_plugins()
|
|
registry.load_plugins()
|
|
|
|
# drop out of maintenance
|
|
# makes sure we did not have an error in reloading and maintenance is still active
|
|
set_maintenance_mode(False)
|
|
|
|
# check git version
|
|
registry.git_is_modern = check_git_version()
|
|
if not registry.git_is_modern: # pragma: no cover # simulating old git seems not worth it for coverage
|
|
log_error(_('Your enviroment has an outdated git version. This prevents InvenTree from loading plugin details.'), 'load')
|
|
|
|
else:
|
|
logger.info("Plugins not enabled - skipping loading sequence") # pragma: no cover
|