mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
replace depreceated values everywhere
This commit is contained in:
parent
81deb8201e
commit
1782974df8
@ -108,7 +108,7 @@ class NotificationMethod:
|
||||
return False
|
||||
|
||||
# Check if method globally enabled
|
||||
plg_instance = registry.plugins.get(plg_cls.PLUGIN_NAME.lower())
|
||||
plg_instance = registry.plugins.get(plg_cls.NAME.lower())
|
||||
if plg_instance and not plg_instance.get_setting(self.GLOBAL_SETTING):
|
||||
return True
|
||||
|
||||
|
@ -24,7 +24,7 @@ class ActionMixin:
|
||||
Action name for this plugin.
|
||||
|
||||
If the ACTION_NAME parameter is empty,
|
||||
uses the PLUGIN_NAME instead.
|
||||
uses the NAME instead.
|
||||
"""
|
||||
if self.ACTION_NAME:
|
||||
return self.ACTION_NAME
|
||||
|
@ -31,7 +31,7 @@ class ActionMixinTests(TestCase):
|
||||
self.action_plugin = TestActionPlugin('user')
|
||||
|
||||
class NameActionPlugin(ActionMixin, InvenTreePlugin):
|
||||
PLUGIN_NAME = 'Aplugin'
|
||||
NAME = 'Aplugin'
|
||||
|
||||
self.action_name = NameActionPlugin('user')
|
||||
|
||||
|
@ -373,7 +373,7 @@ class LabelPrintingMixin:
|
||||
"""
|
||||
Mixin which enables direct printing of stock labels.
|
||||
|
||||
Each plugin must provide a PLUGIN_NAME attribute, which is used to uniquely identify the printer.
|
||||
Each plugin must provide a NAME attribute, which is used to uniquely identify the printer.
|
||||
|
||||
The plugin must also implement the print_label() function
|
||||
"""
|
||||
@ -428,7 +428,7 @@ class APICallMixin:
|
||||
'''
|
||||
A small api call sample
|
||||
'''
|
||||
PLUGIN_NAME = "Sample API Caller"
|
||||
NAME = "Sample API Caller"
|
||||
|
||||
SETTINGS = {
|
||||
'API_TOKEN': {
|
||||
|
@ -147,7 +147,7 @@ class APICallMixinTest(BaseMixinDefinition, TestCase):
|
||||
|
||||
def setUp(self):
|
||||
class MixinCls(APICallMixin, SettingsMixin, InvenTreePlugin):
|
||||
PLUGIN_NAME = "Sample API Caller"
|
||||
NAME = "Sample API Caller"
|
||||
|
||||
SETTINGS = {
|
||||
'API_TOKEN': {
|
||||
|
@ -10,7 +10,7 @@ class SimpleActionPlugin(ActionMixin, InvenTreePlugin):
|
||||
the capability of the ActionMixin class
|
||||
"""
|
||||
|
||||
PLUGIN_NAME = "SimpleActionPlugin"
|
||||
NAME = "SimpleActionPlugin"
|
||||
ACTION_NAME = "simple"
|
||||
|
||||
def perform_action(self):
|
||||
|
@ -24,7 +24,7 @@ from rest_framework.exceptions import ValidationError
|
||||
|
||||
class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin):
|
||||
|
||||
PLUGIN_NAME = "InvenTreeBarcode"
|
||||
NAME = "InvenTreeBarcode"
|
||||
|
||||
def validate(self):
|
||||
"""
|
||||
|
@ -20,7 +20,7 @@ class CoreNotificationsPlugin(SettingsMixin, InvenTreePlugin):
|
||||
Core notification methods for InvenTree
|
||||
"""
|
||||
|
||||
PLUGIN_NAME = "CoreNotificationsPlugin"
|
||||
NAME = "CoreNotificationsPlugin"
|
||||
AUTHOR = _('InvenTree contributors')
|
||||
DESCRIPTION = _('Integrated outgoing notificaton methods')
|
||||
|
||||
|
@ -205,7 +205,7 @@ def get_plugins(pkg, baseclass):
|
||||
Return a list of all modules under a given package.
|
||||
|
||||
- Modules must be a subclass of the provided 'baseclass'
|
||||
- Modules must have a non-empty PLUGIN_NAME parameter
|
||||
- Modules must have a non-empty NAME parameter
|
||||
"""
|
||||
|
||||
plugins = []
|
||||
@ -217,7 +217,7 @@ def get_plugins(pkg, baseclass):
|
||||
# Iterate through each class in the module
|
||||
for item in get_classes(mod):
|
||||
plugin = item[1]
|
||||
if issubclass(plugin, baseclass) and plugin.PLUGIN_NAME:
|
||||
if issubclass(plugin, baseclass) and plugin.NAME:
|
||||
plugins.append(plugin)
|
||||
|
||||
return plugins
|
||||
|
@ -281,8 +281,8 @@ class PluginsRegistry:
|
||||
|
||||
# Check if activated
|
||||
# These checks only use attributes - never use plugin supplied functions -> that would lead to arbitrary code execution!!
|
||||
plug_name = plugin.PLUGIN_NAME
|
||||
plug_key = plugin.PLUGIN_SLUG if getattr(plugin, 'PLUGIN_SLUG', None) else plug_name
|
||||
plug_name = plugin.NAME
|
||||
plug_key = plugin.SLUG if getattr(plugin, 'SLUG', None) else plug_name
|
||||
plug_key = slugify(plug_key) # keys are slugs!
|
||||
try:
|
||||
plugin_db_setting, _ = PluginConfig.objects.get_or_create(key=plug_key, name=plug_name)
|
||||
@ -314,7 +314,7 @@ class PluginsRegistry:
|
||||
# now we can be sure that an admin has activated the plugin
|
||||
# TODO check more stuff -> as of Nov 2021 there are not many checks in place
|
||||
# but we could enhance those to check signatures, run the plugin against a whitelist etc.
|
||||
logger.info(f'Loading integration plugin {plugin.PLUGIN_NAME}')
|
||||
logger.info(f'Loading plugin {plug_name}')
|
||||
|
||||
try:
|
||||
plugin = plugin()
|
||||
@ -322,7 +322,7 @@ class PluginsRegistry:
|
||||
# log error and raise it -> disable plugin
|
||||
handle_error(error, log_name='init')
|
||||
|
||||
logger.debug(f'Loaded integration plugin {plugin.PLUGIN_NAME}')
|
||||
logger.debug(f'Loaded plugin {plug_name}')
|
||||
|
||||
plugin.is_package = was_packaged
|
||||
|
||||
@ -516,7 +516,7 @@ class PluginsRegistry:
|
||||
plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts)
|
||||
except ValueError: # pragma: no cover
|
||||
# plugin is shipped as package
|
||||
plugin_path = plugin.PLUGIN_NAME
|
||||
plugin_path = plugin.NAME
|
||||
return plugin_path
|
||||
|
||||
def deactivate_integration_app(self):
|
||||
|
@ -11,9 +11,9 @@ class EventPluginSample(EventMixin, InvenTreePlugin):
|
||||
A sample plugin which provides supports for triggered events
|
||||
"""
|
||||
|
||||
PLUGIN_NAME = "EventPlugin"
|
||||
PLUGIN_SLUG = "event"
|
||||
PLUGIN_TITLE = "Triggered Events"
|
||||
NAME = "EventPlugin"
|
||||
SLUG = "event"
|
||||
TITLE = "Triggered Events"
|
||||
|
||||
def process_event(self, event, *args, **kwargs):
|
||||
""" Custom event processing """
|
||||
|
@ -8,7 +8,7 @@ class NoIntegrationPlugin(InvenTreePlugin):
|
||||
An basic integration plugin
|
||||
"""
|
||||
|
||||
PLUGIN_NAME = "NoIntegrationPlugin"
|
||||
NAME = "NoIntegrationPlugin"
|
||||
|
||||
|
||||
class WrongIntegrationPlugin(UrlsMixin, InvenTreePlugin):
|
||||
@ -16,4 +16,4 @@ class WrongIntegrationPlugin(UrlsMixin, InvenTreePlugin):
|
||||
An basic integration plugin
|
||||
"""
|
||||
|
||||
PLUGIN_NAME = "WrongIntegrationPlugin"
|
||||
NAME = "WrongIntegrationPlugin"
|
||||
|
@ -9,7 +9,7 @@ class SampleApiCallerPlugin(APICallMixin, SettingsMixin, InvenTreePlugin):
|
||||
"""
|
||||
A small api call sample
|
||||
"""
|
||||
PLUGIN_NAME = "Sample API Caller"
|
||||
NAME = "Sample API Caller"
|
||||
|
||||
SETTINGS = {
|
||||
'API_TOKEN': {
|
||||
|
@ -6,9 +6,9 @@ class BrokenIntegrationPlugin(InvenTreePlugin):
|
||||
"""
|
||||
An very broken integration plugin
|
||||
"""
|
||||
PLUGIN_NAME = 'Test'
|
||||
PLUGIN_TITLE = 'Broken Plugin'
|
||||
PLUGIN_SLUG = 'broken'
|
||||
NAME = 'Test'
|
||||
TITLE = 'Broken Plugin'
|
||||
SLUG = 'broken'
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -14,9 +14,9 @@ class CustomPanelSample(PanelMixin, SettingsMixin, InvenTreePlugin):
|
||||
A sample plugin which renders some custom panels.
|
||||
"""
|
||||
|
||||
PLUGIN_NAME = "CustomPanelExample"
|
||||
PLUGIN_SLUG = "panel"
|
||||
PLUGIN_TITLE = "Custom Panel Example"
|
||||
NAME = "CustomPanelExample"
|
||||
SLUG = "panel"
|
||||
TITLE = "Custom Panel Example"
|
||||
DESCRIPTION = "An example plugin demonstrating how custom panels can be added to the user interface"
|
||||
VERSION = "0.1"
|
||||
|
||||
|
@ -15,9 +15,9 @@ class SampleIntegrationPlugin(AppMixin, SettingsMixin, UrlsMixin, NavigationMixi
|
||||
A full integration plugin example
|
||||
"""
|
||||
|
||||
PLUGIN_NAME = "SampleIntegrationPlugin"
|
||||
PLUGIN_SLUG = "sample"
|
||||
PLUGIN_TITLE = "Sample Plugin"
|
||||
NAME = "SampleIntegrationPlugin"
|
||||
SLUG = "sample"
|
||||
TITLE = "Sample Plugin"
|
||||
|
||||
NAVIGATION_TAB_NAME = "Sample Nav"
|
||||
NAVIGATION_TAB_ICON = 'fas fa-plus'
|
||||
|
@ -20,9 +20,9 @@ class ScheduledTaskPlugin(ScheduleMixin, SettingsMixin, InvenTreePlugin):
|
||||
A sample plugin which provides support for scheduled tasks
|
||||
"""
|
||||
|
||||
PLUGIN_NAME = "ScheduledTasksPlugin"
|
||||
PLUGIN_SLUG = "schedule"
|
||||
PLUGIN_TITLE = "Scheduled Tasks"
|
||||
NAME = "ScheduledTasksPlugin"
|
||||
SLUG = "schedule"
|
||||
TITLE = "Scheduled Tasks"
|
||||
|
||||
SCHEDULED_TASKS = {
|
||||
'member': {
|
||||
|
@ -54,7 +54,7 @@ class ScheduledTaskPluginTests(TestCase):
|
||||
def test_init(self):
|
||||
"""Check that all MixinImplementationErrors raise"""
|
||||
class Base(ScheduleMixin, InvenTreePlugin):
|
||||
PLUGIN_NAME = 'APlugin'
|
||||
NAME = 'APlugin'
|
||||
|
||||
class NoSchedules(Base):
|
||||
"""Plugin without schedules"""
|
||||
|
@ -65,19 +65,19 @@ class InvenTreePluginTests(TestCase):
|
||||
|
||||
class NamedPlugin(InvenTreePlugin):
|
||||
"""a named plugin"""
|
||||
PLUGIN_NAME = 'abc123'
|
||||
NAME = 'abc123'
|
||||
|
||||
self.named_plugin = NamedPlugin()
|
||||
|
||||
class SimpleInvenTreePlugin(InvenTreePlugin):
|
||||
PLUGIN_NAME = 'SimplePlugin'
|
||||
NAME = 'SimplePlugin'
|
||||
|
||||
self.plugin_simple = SimpleInvenTreePlugin()
|
||||
|
||||
class NameInvenTreePlugin(InvenTreePlugin):
|
||||
PLUGIN_NAME = 'Aplugin'
|
||||
PLUGIN_SLUG = 'a'
|
||||
PLUGIN_TITLE = 'a titel'
|
||||
NAME = 'Aplugin'
|
||||
SLUG = 'a'
|
||||
TITLE = 'a titel'
|
||||
PUBLISH_DATE = "1111-11-11"
|
||||
AUTHOR = 'AA BB'
|
||||
DESCRIPTION = 'A description'
|
||||
@ -90,12 +90,12 @@ class InvenTreePluginTests(TestCase):
|
||||
|
||||
def test_basic_plugin_init(self):
|
||||
"""check if a basic plugin intis"""
|
||||
self.assertEqual(self.plugin.PLUGIN_NAME, '')
|
||||
self.assertEqual(self.plugin.NAME, '')
|
||||
self.assertEqual(self.plugin.plugin_name(), '')
|
||||
|
||||
def test_basic_plugin_name(self):
|
||||
"""check if the name of a basic plugin can be set"""
|
||||
self.assertEqual(self.named_plugin.PLUGIN_NAME, 'abc123')
|
||||
self.assertEqual(self.named_plugin.NAME, 'abc123')
|
||||
self.assertEqual(self.named_plugin.plugin_name(), 'abc123')
|
||||
|
||||
def test_basic_is_active(self):
|
||||
|
Loading…
Reference in New Issue
Block a user