move stacks to registry

This commit is contained in:
Matthias 2021-11-20 18:26:41 +01:00
parent 8fbbcb3a8d
commit b1fbac925d
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
4 changed files with 17 additions and 13 deletions

View File

@ -884,9 +884,6 @@ if DEBUG or TESTING:
PLUGINS = [] PLUGINS = []
INTEGRATION_PLUGIN_GLOBALSETTING = {} INTEGRATION_PLUGIN_GLOBALSETTING = {}
INTEGRATION_APPS_PATHS = [] # Holds all added plugin_paths
INTEGRATION_ERRORS = {} # Holds discovering errors
# Test settings # Test settings
PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # used to force enable everything plugin PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # used to force enable everything plugin
PLUGIN_TESTING_SETUP = get_setting('PLUGIN_TESTING_SETUP', False) PLUGIN_TESTING_SETUP = get_setting('PLUGIN_TESTING_SETUP', False)

View File

@ -10,12 +10,14 @@ from django.conf import settings
# region logging / errors # region logging / errors
def log_plugin_error(error, reference: str = 'general'): def log_plugin_error(error, reference: str = 'general'):
from plugin import plugin_reg
# make sure the registry is set up # make sure the registry is set up
if reference not in settings.INTEGRATION_ERRORS: if reference not in plugin_reg.errors:
settings.INTEGRATION_ERRORS[reference] = [] plugin_reg.errors[reference] = []
# add error to stack # add error to stack
settings.INTEGRATION_ERRORS[reference].append(error) plugin_reg.errors[reference].append(error)
class IntegrationPluginError(Exception): class IntegrationPluginError(Exception):

View File

@ -43,6 +43,11 @@ class Plugins:
self.is_loading = False self.is_loading = False
self.apps_loading = True # Marks if apps were reloaded yet self.apps_loading = True # Marks if apps were reloaded yet
# integration specific
self.installed_apps = [] # Holds all added plugin_paths
self.errors = {} # Holds discovering errors
# region public plugin functions # region public plugin functions
def load_plugins(self): def load_plugins(self):
"""load and activate all IntegrationPlugins""" """load and activate all IntegrationPlugins"""
@ -265,7 +270,7 @@ class Plugins:
plugin_path = self._get_plugin_path(plugin) plugin_path = self._get_plugin_path(plugin)
if plugin_path not in settings.INSTALLED_APPS: if plugin_path not in settings.INSTALLED_APPS:
settings.INSTALLED_APPS += [plugin_path] settings.INSTALLED_APPS += [plugin_path]
settings.INTEGRATION_APPS_PATHS += [plugin_path] self.installed_apps += [plugin_path]
apps_changed = True apps_changed = True
# if apps were changed or force loading base apps -> reload # if apps were changed or force loading base apps -> reload
@ -288,7 +293,7 @@ class Plugins:
this is needed if plugins were loaded earlier and then reloaded as models and admins rely on imports this is needed if plugins were loaded earlier and then reloaded as models and admins rely on imports
those register models and admin in their respective objects (e.g. admin.site for admin) those register models and admin in their respective objects (e.g. admin.site for admin)
""" """
for plugin_path in settings.INTEGRATION_APPS_PATHS: for plugin_path in self.installed_apps:
try: try:
app_name = plugin_path.split('.')[-1] app_name = plugin_path.split('.')[-1]
app_config = apps.get_app_config(app_name) app_config = apps.get_app_config(app_name)
@ -332,7 +337,7 @@ class Plugins:
def deactivate_integration_app(self): def deactivate_integration_app(self):
"""deactivate integration app - some magic required""" """deactivate integration app - some magic required"""
# unregister models from admin # unregister models from admin
for plugin_path in settings.INTEGRATION_APPS_PATHS: for plugin_path in self.installed_apps:
models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed
app_name = plugin_path.split('.')[-1] app_name = plugin_path.split('.')[-1]
try: try:
@ -370,11 +375,11 @@ class Plugins:
self._update_urls() self._update_urls()
def _clean_installed_apps(self): def _clean_installed_apps(self):
for plugin in settings.INTEGRATION_APPS_PATHS: for plugin in self.installed_apps:
if plugin in settings.INSTALLED_APPS: if plugin in settings.INSTALLED_APPS:
settings.INSTALLED_APPS.remove(plugin) settings.INSTALLED_APPS.remove(plugin)
settings.INTEGRATION_APPS_PATHS = [] self.installed_apps = []
def _clean_registry(self): def _clean_registry(self):
# remove all plugins from registry # remove all plugins from registry

View File

@ -57,4 +57,4 @@ def safe_url(view_name, *args, **kwargs):
@register.simple_tag() @register.simple_tag()
def plugin_errors(*args, **kwargs): def plugin_errors(*args, **kwargs):
"""Return all plugin errors""" """Return all plugin errors"""
return djangosettings.INTEGRATION_ERRORS return plugin_reg.errors