mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Rename registry to make it clearer
This commit is contained in:
parent
0283214034
commit
f53e66d4c3
@ -19,7 +19,7 @@ from .views import AjaxView
|
||||
from .version import inventreeVersion, inventreeApiVersion, inventreeInstanceName
|
||||
from .status import is_worker_running
|
||||
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
|
||||
class InfoView(AjaxView):
|
||||
@ -101,7 +101,7 @@ class ActionPluginView(APIView):
|
||||
'error': _("No action specified")
|
||||
})
|
||||
|
||||
action_plugins = plugin_registry.with_mixin('action')
|
||||
action_plugins = registry.with_mixin('action')
|
||||
for plugin in action_plugins:
|
||||
if plugin.action_name() == action:
|
||||
# TODO @matmair use easier syntax once InvenTree 0.7.0 is released
|
||||
|
@ -13,7 +13,7 @@ from stock.models import StockItem
|
||||
from stock.serializers import StockItemSerializer
|
||||
|
||||
from barcodes.barcode import hash_barcode
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
|
||||
class BarcodeScan(APIView):
|
||||
@ -53,7 +53,7 @@ class BarcodeScan(APIView):
|
||||
if 'barcode' not in data:
|
||||
raise ValidationError({'barcode': _('Must provide barcode_data parameter')})
|
||||
|
||||
plugins = plugin_registry.with_mixin('barcode')
|
||||
plugins = registry.with_mixin('barcode')
|
||||
|
||||
barcode_data = data.get('barcode')
|
||||
|
||||
@ -161,7 +161,7 @@ class BarcodeAssign(APIView):
|
||||
except (ValueError, StockItem.DoesNotExist):
|
||||
raise ValidationError({'stockitem': _('No matching stock item found')})
|
||||
|
||||
plugins = plugin_registry.with_mixin('barcode')
|
||||
plugins = registry.with_mixin('barcode')
|
||||
|
||||
plugin = None
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
Utility file to enable simper imports
|
||||
"""
|
||||
|
||||
from .registry import plugin_registry
|
||||
from .registry import registry
|
||||
from .plugin import InvenTreePlugin
|
||||
from .integration import IntegrationPluginBase
|
||||
from .action import ActionPlugin
|
||||
@ -13,7 +13,7 @@ __all__ = [
|
||||
'ActionPlugin',
|
||||
'IntegrationPluginBase',
|
||||
'InvenTreePlugin',
|
||||
'plugin_registry',
|
||||
'registry',
|
||||
'MixinNotImplementedError',
|
||||
'MixinImplementationError',
|
||||
]
|
||||
|
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
||||
from django.contrib import admin
|
||||
|
||||
import plugin.models as models
|
||||
import plugin.registry as registry
|
||||
import plugin.registry as pl_registry
|
||||
|
||||
|
||||
def plugin_update(queryset, new_status: bool):
|
||||
@ -23,7 +23,7 @@ def plugin_update(queryset, new_status: bool):
|
||||
|
||||
# Reload plugins if they changed
|
||||
if apps_changed:
|
||||
registry.plugin_registry.reload_plugins()
|
||||
pl_registry.registry.reload_plugins()
|
||||
|
||||
|
||||
@admin.action(description='Activate plugin(s)')
|
||||
|
@ -4,17 +4,17 @@ from __future__ import unicode_literals
|
||||
from django.apps import AppConfig
|
||||
from maintenance_mode.core import set_maintenance_mode
|
||||
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
|
||||
class PluginAppConfig(AppConfig):
|
||||
name = 'plugin'
|
||||
|
||||
def ready(self):
|
||||
if not plugin_registry.is_loading:
|
||||
if not registry.is_loading:
|
||||
# this is the first startup
|
||||
plugin_registry.collect_plugins()
|
||||
plugin_registry.load_plugins()
|
||||
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
|
||||
|
@ -17,7 +17,7 @@ from common.models import InvenTreeSetting
|
||||
from InvenTree.ready import canAppAccessDatabase
|
||||
from InvenTree.tasks import offload_task
|
||||
|
||||
from plugin.registry import plugin_registry
|
||||
from plugin.registry import registry
|
||||
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
@ -60,7 +60,7 @@ def register_event(event, *args, **kwargs):
|
||||
|
||||
with transaction.atomic():
|
||||
|
||||
for slug, plugin in plugin_registry.plugins.items():
|
||||
for slug, plugin in registry.plugins.items():
|
||||
|
||||
if plugin.mixin_enabled('events'):
|
||||
|
||||
@ -91,7 +91,7 @@ def process_event(plugin_slug, event, *args, **kwargs):
|
||||
|
||||
logger.info(f"Plugin '{plugin_slug}' is processing triggered event '{event}'")
|
||||
|
||||
plugin = plugin_registry.plugins[plugin_slug]
|
||||
plugin = registry.plugins[plugin_slug]
|
||||
|
||||
plugin.process_event(event, *args, **kwargs)
|
||||
|
||||
|
@ -10,14 +10,14 @@ from django.conf import settings
|
||||
|
||||
# region logging / errors
|
||||
def log_plugin_error(error, reference: str = 'general'):
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
# make sure the registry is set up
|
||||
if reference not in plugin_registry.errors:
|
||||
plugin_registry.errors[reference] = []
|
||||
if reference not in registry.errors:
|
||||
registry.errors[reference] = []
|
||||
|
||||
# add error to stack
|
||||
plugin_registry.errors[reference].append(error)
|
||||
registry.errors[reference].append(error)
|
||||
|
||||
|
||||
class IntegrationPluginError(Exception):
|
||||
|
@ -4,7 +4,7 @@ load templates for loaded plugins
|
||||
from django.template.loaders.filesystem import Loader as FilesystemLoader
|
||||
from pathlib import Path
|
||||
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
|
||||
class PluginTemplateLoader(FilesystemLoader):
|
||||
@ -12,7 +12,7 @@ class PluginTemplateLoader(FilesystemLoader):
|
||||
def get_dirs(self):
|
||||
dirname = 'templates'
|
||||
template_dirs = []
|
||||
for plugin in plugin_registry.plugins.values():
|
||||
for plugin in registry.plugins.values():
|
||||
new_path = Path(plugin.path) / dirname
|
||||
if Path(new_path).is_dir():
|
||||
template_dirs.append(new_path)
|
||||
|
@ -547,4 +547,4 @@ class PluginsRegistry:
|
||||
# endregion
|
||||
|
||||
|
||||
plugin_registry = PluginsRegistry()
|
||||
registry = PluginsRegistry()
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
|
||||
class SampleApiCallerPluginTests(TestCase):
|
||||
@ -11,8 +11,8 @@ class SampleApiCallerPluginTests(TestCase):
|
||||
def test_return(self):
|
||||
"""check if the external api call works"""
|
||||
# The plugin should be defined
|
||||
self.assertIn('sample-api-caller', plugin_registry.plugins)
|
||||
plg = plugin_registry.plugins['sample-api-caller']
|
||||
self.assertIn('sample-api-caller', registry.plugins)
|
||||
plg = registry.plugins['sample-api-caller']
|
||||
self.assertTrue(plg)
|
||||
|
||||
# do an api call
|
||||
|
@ -7,7 +7,7 @@ from django import template
|
||||
from django.urls import reverse
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
|
||||
register = template.Library()
|
||||
@ -16,19 +16,19 @@ register = template.Library()
|
||||
@register.simple_tag()
|
||||
def plugin_list(*args, **kwargs):
|
||||
""" Return a list of all installed integration plugins """
|
||||
return plugin_registry.plugins
|
||||
return registry.plugins
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def inactive_plugin_list(*args, **kwargs):
|
||||
""" Return a list of all inactive integration plugins """
|
||||
return plugin_registry.plugins_inactive
|
||||
return registry.plugins_inactive
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def plugin_settings(plugin, *args, **kwargs):
|
||||
""" Return a list of all custom settings for a plugin """
|
||||
return plugin_registry.mixins_settings.get(plugin)
|
||||
return registry.mixins_settings.get(plugin)
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
@ -57,4 +57,4 @@ def safe_url(view_name, *args, **kwargs):
|
||||
@register.simple_tag()
|
||||
def plugin_errors(*args, **kwargs):
|
||||
"""Return all plugin errors"""
|
||||
return plugin_registry.errors
|
||||
return registry.errors
|
||||
|
@ -64,14 +64,14 @@ class PluginDetailAPITest(InvenTreeAPITestCase):
|
||||
Test the PluginConfig action commands
|
||||
"""
|
||||
from plugin.models import PluginConfig
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
url = reverse('admin:plugin_pluginconfig_changelist')
|
||||
fixtures = PluginConfig.objects.all()
|
||||
|
||||
# check if plugins were registered -> in some test setups the startup has no db access
|
||||
if not fixtures:
|
||||
plugin_registry.reload_plugins()
|
||||
registry.reload_plugins()
|
||||
fixtures = PluginConfig.objects.all()
|
||||
|
||||
print([str(a) for a in fixtures])
|
||||
|
@ -9,7 +9,7 @@ import plugin.integration
|
||||
from plugin.samples.integration.sample import SampleIntegrationPlugin
|
||||
from plugin.samples.integration.another_sample import WrongIntegrationPlugin, NoIntegrationPlugin
|
||||
import plugin.templatetags.plugin_extras as plugin_tags
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
|
||||
class InvenTreePluginTests(TestCase):
|
||||
@ -44,17 +44,17 @@ class PluginTagTests(TestCase):
|
||||
|
||||
def test_tag_plugin_list(self):
|
||||
"""test that all plugins are listed"""
|
||||
self.assertEqual(plugin_tags.plugin_list(), plugin_registry.plugins)
|
||||
self.assertEqual(plugin_tags.plugin_list(), registry.plugins)
|
||||
|
||||
def test_tag_incative_plugin_list(self):
|
||||
"""test that all inactive plugins are listed"""
|
||||
self.assertEqual(plugin_tags.inactive_plugin_list(), plugin_registry.plugins_inactive)
|
||||
self.assertEqual(plugin_tags.inactive_plugin_list(), registry.plugins_inactive)
|
||||
|
||||
def test_tag_plugin_settings(self):
|
||||
"""check all plugins are listed"""
|
||||
self.assertEqual(
|
||||
plugin_tags.plugin_settings(self.sample),
|
||||
plugin_registry.mixins_settings.get(self.sample)
|
||||
registry.mixins_settings.get(self.sample)
|
||||
)
|
||||
|
||||
def test_tag_mixin_enabled(self):
|
||||
@ -76,4 +76,4 @@ class PluginTagTests(TestCase):
|
||||
|
||||
def test_tag_plugin_errors(self):
|
||||
"""test that all errors are listed"""
|
||||
self.assertEqual(plugin_tags.plugin_errors(), plugin_registry.errors)
|
||||
self.assertEqual(plugin_tags.plugin_errors(), registry.errors)
|
||||
|
@ -4,7 +4,7 @@ URL lookup for plugin app
|
||||
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from plugin import plugin_registry
|
||||
from plugin import registry
|
||||
|
||||
|
||||
PLUGIN_BASE = 'plugin' # Constant for links
|
||||
@ -17,7 +17,7 @@ def get_plugin_urls():
|
||||
|
||||
urls = []
|
||||
|
||||
for plugin in plugin_registry.plugins.values():
|
||||
for plugin in registry.plugins.values():
|
||||
if plugin.mixin_enabled('urls'):
|
||||
urls.append(plugin.urlpatterns)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user