mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 11:10:54 +00:00
Refactor mixin_enabled calls (#9825)
- Ensure the enumerated values are used
This commit is contained in:
@ -12,6 +12,7 @@ import InvenTree.exceptions
|
|||||||
from common.settings import get_global_setting
|
from common.settings import get_global_setting
|
||||||
from InvenTree.ready import canAppAccessDatabase, isImportingData
|
from InvenTree.ready import canAppAccessDatabase, isImportingData
|
||||||
from InvenTree.tasks import offload_task
|
from InvenTree.tasks import offload_task
|
||||||
|
from plugin import PluginMixinEnum
|
||||||
from plugin.registry import registry
|
from plugin.registry import registry
|
||||||
|
|
||||||
tracer = trace.get_tracer(__name__)
|
tracer = trace.get_tracer(__name__)
|
||||||
@ -73,7 +74,7 @@ def register_event(event, *args, **kwargs):
|
|||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for slug, plugin in registry.plugins.items():
|
for slug, plugin in registry.plugins.items():
|
||||||
if not plugin.mixin_enabled('events'):
|
if not plugin.mixin_enabled(PluginMixinEnum.EVENTS):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Only allow event registering for 'active' plugins
|
# Only allow event registering for 'active' plugins
|
||||||
|
@ -57,7 +57,7 @@ class AppMixin:
|
|||||||
|
|
||||||
# add them to the INSTALLED_APPS
|
# add them to the INSTALLED_APPS
|
||||||
for _key, plugin in plugins:
|
for _key, plugin in plugins:
|
||||||
if plugin.mixin_enabled('app'):
|
if plugin.mixin_enabled(PluginMixinEnum.APP):
|
||||||
plugin_path = cls._get_plugin_path(plugin)
|
plugin_path = cls._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]
|
||||||
|
@ -67,7 +67,10 @@ class ScheduleMixin:
|
|||||||
|
|
||||||
if settings.PLUGIN_TESTING or get_global_setting('ENABLE_PLUGINS_SCHEDULE'):
|
if settings.PLUGIN_TESTING or get_global_setting('ENABLE_PLUGINS_SCHEDULE'):
|
||||||
for _key, plugin in plugins:
|
for _key, plugin in plugins:
|
||||||
if plugin.mixin_enabled('schedule') and plugin.is_active():
|
if (
|
||||||
|
plugin.mixin_enabled(PluginMixinEnum.SCHEDULE)
|
||||||
|
and plugin.is_active()
|
||||||
|
):
|
||||||
# Only active tasks for plugins which are enabled
|
# Only active tasks for plugins which are enabled
|
||||||
plugin.register_tasks()
|
plugin.register_tasks()
|
||||||
task_keys += plugin.get_task_names()
|
task_keys += plugin.get_task_names()
|
||||||
|
@ -47,7 +47,7 @@ class SettingsMixin:
|
|||||||
registry.mixins_settings = {}
|
registry.mixins_settings = {}
|
||||||
|
|
||||||
for slug, plugin in plugins:
|
for slug, plugin in plugins:
|
||||||
if plugin.mixin_enabled('settings'):
|
if plugin.mixin_enabled(PluginMixinEnum.SETTINGS):
|
||||||
plugin_setting = plugin.settings
|
plugin_setting = plugin.settings
|
||||||
registry.mixins_settings[slug] = plugin_setting
|
registry.mixins_settings[slug] = plugin_setting
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class UrlsMixin:
|
|||||||
urls_changed = False
|
urls_changed = False
|
||||||
# check whether an activated plugin extends UrlsMixin
|
# check whether an activated plugin extends UrlsMixin
|
||||||
for _key, plugin in plugins:
|
for _key, plugin in plugins:
|
||||||
if plugin.mixin_enabled('urls'):
|
if plugin.mixin_enabled(PluginMixinEnum.URLS):
|
||||||
urls_changed = True
|
urls_changed = True
|
||||||
# if apps were changed or force loading base apps -> reload
|
# if apps were changed or force loading base apps -> reload
|
||||||
if urls_changed or force_reload or full_reload:
|
if urls_changed or force_reload or full_reload:
|
||||||
|
@ -4,6 +4,7 @@ from django.conf import settings
|
|||||||
from django.urls import include, re_path
|
from django.urls import include, re_path
|
||||||
|
|
||||||
from common.validators import get_global_setting
|
from common.validators import get_global_setting
|
||||||
|
from plugin import PluginMixinEnum
|
||||||
|
|
||||||
PLUGIN_BASE = 'plugin' # Constant for links
|
PLUGIN_BASE = 'plugin' # Constant for links
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ def get_plugin_urls():
|
|||||||
|
|
||||||
if get_global_setting('ENABLE_PLUGINS_URL', False) or settings.PLUGIN_TESTING_SETUP:
|
if get_global_setting('ENABLE_PLUGINS_URL', False) or settings.PLUGIN_TESTING_SETUP:
|
||||||
for plugin in registry.plugins.values():
|
for plugin in registry.plugins.values():
|
||||||
if plugin.mixin_enabled('urls'):
|
if plugin.mixin_enabled(PluginMixinEnum.URLS):
|
||||||
urls.append(plugin.urlpatterns)
|
urls.append(plugin.urlpatterns)
|
||||||
|
|
||||||
return re_path(f'^{PLUGIN_BASE}/', include((urls, 'plugin')))
|
return re_path(f'^{PLUGIN_BASE}/', include((urls, 'plugin')))
|
||||||
|
@ -11,8 +11,6 @@ from django_filters.rest_framework import DjangoFilterBackend
|
|||||||
from rest_framework.generics import GenericAPIView
|
from rest_framework.generics import GenericAPIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
import InvenTree.exceptions
|
|
||||||
import InvenTree.helpers
|
|
||||||
import InvenTree.permissions
|
import InvenTree.permissions
|
||||||
import report.helpers
|
import report.helpers
|
||||||
import report.models
|
import report.models
|
||||||
@ -22,6 +20,7 @@ from common.serializers import DataOutputSerializer
|
|||||||
from InvenTree.api import MetadataView
|
from InvenTree.api import MetadataView
|
||||||
from InvenTree.filters import InvenTreeSearchFilter
|
from InvenTree.filters import InvenTreeSearchFilter
|
||||||
from InvenTree.mixins import ListCreateAPI, RetrieveUpdateDestroyAPI
|
from InvenTree.mixins import ListCreateAPI, RetrieveUpdateDestroyAPI
|
||||||
|
from plugin import PluginMixinEnum
|
||||||
from plugin.builtin.labels.inventree_label import InvenTreeLabelPlugin
|
from plugin.builtin.labels.inventree_label import InvenTreeLabelPlugin
|
||||||
|
|
||||||
|
|
||||||
@ -121,7 +120,7 @@ class LabelPrint(GenericAPIView):
|
|||||||
error = _('Plugin not found')
|
error = _('Plugin not found')
|
||||||
elif not plugin.is_active():
|
elif not plugin.is_active():
|
||||||
error = _('Plugin is not active')
|
error = _('Plugin is not active')
|
||||||
elif not plugin.mixin_enabled('labels'):
|
elif not plugin.mixin_enabled(PluginMixinEnum.LABELS):
|
||||||
error = _('Plugin does not support label printing')
|
error = _('Plugin does not support label printing')
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
|
Reference in New Issue
Block a user