mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
move invenTreePlugin to new class
to enable depreceation
This commit is contained in:
parent
52d90cef46
commit
2a7ad93173
@ -250,9 +250,9 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
plugin = kwargs.pop('plugin', None)
|
plugin = kwargs.pop('plugin', None)
|
||||||
|
|
||||||
if plugin:
|
if plugin:
|
||||||
from plugin import InvenTreePlugin
|
from plugin import InvenTreePluginBase
|
||||||
|
|
||||||
if issubclass(plugin.__class__, InvenTreePlugin):
|
if issubclass(plugin.__class__, InvenTreePluginBase):
|
||||||
plugin = plugin.plugin_config()
|
plugin = plugin.plugin_config()
|
||||||
|
|
||||||
kwargs['plugin'] = plugin
|
kwargs['plugin'] = plugin
|
||||||
|
@ -3,7 +3,7 @@ Utility file to enable simper imports
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from .registry import registry
|
from .registry import registry
|
||||||
from .plugin import AAInvenTreePlugin as InvenTreePlugin
|
from .plugin import InvenTreePluginBase
|
||||||
from .integration import IntegrationPluginBase
|
from .integration import IntegrationPluginBase
|
||||||
from .action import ActionPlugin
|
from .action import ActionPlugin
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ from .helpers import MixinNotImplementedError, MixinImplementationError
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
'ActionPlugin',
|
'ActionPlugin',
|
||||||
'IntegrationPluginBase',
|
'IntegrationPluginBase',
|
||||||
'InvenTreePlugin',
|
'InvenTreePluginBase',
|
||||||
'registry',
|
'registry',
|
||||||
'MixinNotImplementedError',
|
'MixinNotImplementedError',
|
||||||
'MixinImplementationError',
|
'MixinImplementationError',
|
||||||
|
@ -13,7 +13,7 @@ from django.urls.base import reverse
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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
|
from plugin.helpers import get_git_log, GitStatus
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class MixinBase:
|
|||||||
return mixins
|
return mixins
|
||||||
|
|
||||||
|
|
||||||
class IntegrationPluginBase(MixinBase, plugin.InvenTreePlugin):
|
class IntegrationPluginBase(MixinBase, plugin_base.InvenTreePluginBase):
|
||||||
"""
|
"""
|
||||||
The IntegrationPluginBase class is used to integrate with 3rd party software
|
The IntegrationPluginBase class is used to integrate with 3rd party software
|
||||||
"""
|
"""
|
||||||
|
@ -10,7 +10,7 @@ from django.db import models
|
|||||||
|
|
||||||
import common.models
|
import common.models
|
||||||
|
|
||||||
from plugin import InvenTreePlugin, registry
|
from plugin import InvenTreePluginBase, registry
|
||||||
|
|
||||||
|
|
||||||
class PluginConfig(models.Model):
|
class PluginConfig(models.Model):
|
||||||
@ -164,7 +164,7 @@ class PluginSetting(common.models.BaseInvenTreeSetting):
|
|||||||
|
|
||||||
if plugin:
|
if plugin:
|
||||||
|
|
||||||
if issubclass(plugin.__class__, InvenTreePlugin):
|
if issubclass(plugin.__class__, InvenTreePluginBase):
|
||||||
plugin = plugin.plugin_config()
|
plugin = plugin.plugin_config()
|
||||||
|
|
||||||
kwargs['settings'] = registry.mixins_settings.get(plugin.key, {})
|
kwargs['settings'] = registry.mixins_settings.get(plugin.key, {})
|
||||||
@ -182,7 +182,7 @@ class PluginSetting(common.models.BaseInvenTreeSetting):
|
|||||||
plugin = kwargs.get('plugin', None)
|
plugin = kwargs.get('plugin', None)
|
||||||
|
|
||||||
if plugin:
|
if plugin:
|
||||||
if issubclass(plugin.__class__, InvenTreePlugin):
|
if issubclass(plugin.__class__, InvenTreePluginBase):
|
||||||
plugin = plugin.plugin_config()
|
plugin = plugin.plugin_config()
|
||||||
filters['plugin'] = plugin
|
filters['plugin'] = plugin
|
||||||
|
|
||||||
|
@ -2,14 +2,16 @@
|
|||||||
"""
|
"""
|
||||||
Base Class for InvenTree plugins
|
Base Class for InvenTree plugins
|
||||||
"""
|
"""
|
||||||
|
import warnings
|
||||||
|
|
||||||
from django.db.utils import OperationalError, ProgrammingError
|
from django.db.utils import OperationalError, ProgrammingError
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
|
|
||||||
|
|
||||||
class AAInvenTreePlugin():
|
class InvenTreePluginBase():
|
||||||
"""
|
"""
|
||||||
Base class for a plugin
|
Base class for a plugin
|
||||||
|
DO NOT USE THIS DIRECTLY, USE plugin.IntegrationPluginBase
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -82,3 +84,13 @@ class AAInvenTreePlugin():
|
|||||||
return cfg.active
|
return cfg.active
|
||||||
else:
|
else:
|
||||||
return False
|
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__()
|
||||||
|
@ -4,20 +4,19 @@ Unit tests for plugins
|
|||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
import plugin.plugin
|
|
||||||
import plugin.integration
|
import plugin.integration
|
||||||
from plugin.samples.integration.sample import SampleIntegrationPlugin
|
from plugin.samples.integration.sample import SampleIntegrationPlugin
|
||||||
from plugin.samples.integration.another_sample import WrongIntegrationPlugin, NoIntegrationPlugin
|
from plugin.samples.integration.another_sample import WrongIntegrationPlugin, NoIntegrationPlugin
|
||||||
import plugin.templatetags.plugin_extras as plugin_tags
|
import plugin.templatetags.plugin_extras as plugin_tags
|
||||||
from plugin import registry
|
from plugin import registry, InvenTreePluginBase
|
||||||
|
|
||||||
|
|
||||||
class InvenTreePluginTests(TestCase):
|
class InvenTreePluginTests(TestCase):
|
||||||
""" Tests for InvenTreePlugin """
|
""" Tests for InvenTreePlugin """
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.plugin = plugin.plugin.InvenTreePlugin()
|
self.plugin = InvenTreePluginBase()
|
||||||
|
|
||||||
class NamedPlugin(plugin.plugin.InvenTreePlugin):
|
class NamedPlugin(InvenTreePluginBase):
|
||||||
"""a named plugin"""
|
"""a named plugin"""
|
||||||
PLUGIN_NAME = 'abc123'
|
PLUGIN_NAME = 'abc123'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user