From 2a7ad931730201a8ae64d64e0be561d9c429a2c1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 11 Jan 2022 01:41:33 +0100 Subject: [PATCH] move invenTreePlugin to new class to enable depreceation --- InvenTree/common/models.py | 4 ++-- InvenTree/plugin/__init__.py | 4 ++-- InvenTree/plugin/integration.py | 4 ++-- InvenTree/plugin/models.py | 6 +++--- InvenTree/plugin/plugin.py | 14 +++++++++++++- InvenTree/plugin/test_plugin.py | 7 +++---- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 50c95966cc..f0d19b3532 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -250,9 +250,9 @@ class BaseInvenTreeSetting(models.Model): plugin = kwargs.pop('plugin', None) if plugin: - from plugin import InvenTreePlugin + from plugin import InvenTreePluginBase - if issubclass(plugin.__class__, InvenTreePlugin): + if issubclass(plugin.__class__, InvenTreePluginBase): plugin = plugin.plugin_config() kwargs['plugin'] = plugin diff --git a/InvenTree/plugin/__init__.py b/InvenTree/plugin/__init__.py index 4aef9e3cb9..b8e40e4271 100644 --- a/InvenTree/plugin/__init__.py +++ b/InvenTree/plugin/__init__.py @@ -3,7 +3,7 @@ Utility file to enable simper imports """ from .registry import registry -from .plugin import AAInvenTreePlugin as InvenTreePlugin +from .plugin import InvenTreePluginBase from .integration import IntegrationPluginBase from .action import ActionPlugin @@ -12,7 +12,7 @@ from .helpers import MixinNotImplementedError, MixinImplementationError __all__ = [ 'ActionPlugin', 'IntegrationPluginBase', - 'InvenTreePlugin', + 'InvenTreePluginBase', 'registry', 'MixinNotImplementedError', 'MixinImplementationError', diff --git a/InvenTree/plugin/integration.py b/InvenTree/plugin/integration.py index c96bcb7f6e..33afae852c 100644 --- a/InvenTree/plugin/integration.py +++ b/InvenTree/plugin/integration.py @@ -13,7 +13,7 @@ from django.urls.base import reverse from django.conf import settings from django.utils.translation import ugettext_lazy as _ -import plugin.plugin as plugin +import plugin.plugin as plugin_base from plugin.helpers import get_git_log, GitStatus @@ -67,7 +67,7 @@ class MixinBase: return mixins -class IntegrationPluginBase(MixinBase, plugin.InvenTreePlugin): +class IntegrationPluginBase(MixinBase, plugin_base.InvenTreePluginBase): """ The IntegrationPluginBase class is used to integrate with 3rd party software """ diff --git a/InvenTree/plugin/models.py b/InvenTree/plugin/models.py index 8eef92acea..30735e7510 100644 --- a/InvenTree/plugin/models.py +++ b/InvenTree/plugin/models.py @@ -10,7 +10,7 @@ from django.db import models import common.models -from plugin import InvenTreePlugin, registry +from plugin import InvenTreePluginBase, registry class PluginConfig(models.Model): @@ -164,7 +164,7 @@ class PluginSetting(common.models.BaseInvenTreeSetting): if plugin: - if issubclass(plugin.__class__, InvenTreePlugin): + if issubclass(plugin.__class__, InvenTreePluginBase): plugin = plugin.plugin_config() kwargs['settings'] = registry.mixins_settings.get(plugin.key, {}) @@ -182,7 +182,7 @@ class PluginSetting(common.models.BaseInvenTreeSetting): plugin = kwargs.get('plugin', None) if plugin: - if issubclass(plugin.__class__, InvenTreePlugin): + if issubclass(plugin.__class__, InvenTreePluginBase): plugin = plugin.plugin_config() filters['plugin'] = plugin diff --git a/InvenTree/plugin/plugin.py b/InvenTree/plugin/plugin.py index 4295c5741f..9abbcc041e 100644 --- a/InvenTree/plugin/plugin.py +++ b/InvenTree/plugin/plugin.py @@ -2,14 +2,16 @@ """ Base Class for InvenTree plugins """ +import warnings from django.db.utils import OperationalError, ProgrammingError from django.utils.text import slugify -class AAInvenTreePlugin(): +class InvenTreePluginBase(): """ Base class for a plugin + DO NOT USE THIS DIRECTLY, USE plugin.IntegrationPluginBase """ def __init__(self): @@ -82,3 +84,13 @@ class AAInvenTreePlugin(): return cfg.active else: return False + + +# TODO @matmair remove after InvenTree 0.7.0 release +class InvenTreePlugin(InvenTreePluginBase): + """ + This is here for leagcy reasons and will be removed in the next major release + """ + def __init__(self): + warnings.warn("Using the InvenTreePlugin is depreceated", DeprecationWarning) + super().__init__() diff --git a/InvenTree/plugin/test_plugin.py b/InvenTree/plugin/test_plugin.py index b067326f69..e73664c668 100644 --- a/InvenTree/plugin/test_plugin.py +++ b/InvenTree/plugin/test_plugin.py @@ -4,20 +4,19 @@ Unit tests for plugins from django.test import TestCase -import plugin.plugin 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 registry +from plugin import registry, InvenTreePluginBase class InvenTreePluginTests(TestCase): """ Tests for InvenTreePlugin """ def setUp(self): - self.plugin = plugin.plugin.InvenTreePlugin() + self.plugin = InvenTreePluginBase() - class NamedPlugin(plugin.plugin.InvenTreePlugin): + class NamedPlugin(InvenTreePluginBase): """a named plugin""" PLUGIN_NAME = 'abc123'