Merge pull request #2489 from SchrodingersGat/plugin-bug-fix

Plugin code bug fix
This commit is contained in:
Oliver 2021-12-31 15:16:21 +11:00 committed by GitHub
commit 30cd7b2196
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 38 deletions

View File

@ -1,44 +1,45 @@
"""default mixins for IntegrationMixins"""
"""
Plugin mixin classes
"""
from django.conf.urls import url, include
from plugin.urls import PLUGIN_BASE
class GlobalSettingsMixin:
"""Mixin that enables global settings for the plugin"""
class SettingsMixin:
"""
Mixin that enables global settings for the plugin
"""
class MixinMeta:
"""meta options for this mixin"""
MIXIN_NAME = 'Global settings'
MIXIN_NAME = 'Settings'
def __init__(self):
super().__init__()
self.add_mixin('globalsettings', 'has_globalsettings', __class__)
self.globalsettings = self.setup_globalsettings()
def setup_globalsettings(self):
"""
setup global settings for this plugin
"""
return getattr(self, 'GLOBALSETTINGS', None)
self.add_mixin('settings', 'has_globalsettings', __class__)
self.globalsettings = getattr(self, 'SETTINGS', None)
@property
def has_globalsettings(self):
"""
does this plugin use custom global settings
Does this plugin use custom global settings
"""
return bool(self.globalsettings)
@property
def globalsettingspatterns(self):
"""
get patterns for InvenTreeSetting defintion
Get patterns for InvenTreeSetting defintion
"""
if self.has_globalsettings:
return {f'PLUGIN_{self.slug.upper()}_{key}': value for key, value in self.globalsettings.items()}
return None
def _globalsetting_name(self, key):
"""get global name of setting"""
"""
Get global name of setting
"""
return f'PLUGIN_{self.slug.upper()}_{key}'
def get_globalsetting(self, key):
@ -57,9 +58,11 @@ class GlobalSettingsMixin:
class UrlsMixin:
"""Mixin that enables urls for the plugin"""
"""
Mixin that enables custom URLs for the plugin
"""
class MixinMeta:
"""meta options for this mixin"""
MIXIN_NAME = 'URLs'
def __init__(self):
@ -105,7 +108,10 @@ class UrlsMixin:
class NavigationMixin:
"""Mixin that enables adding navigation links with the plugin"""
"""
Mixin that enables custom navigation links with the plugin
"""
NAVIGATION_TAB_NAME = None
NAVIGATION_TAB_ICON = "fas fa-question"
@ -152,7 +158,10 @@ class NavigationMixin:
class AppMixin:
"""Mixin that enables full django app functions for a plugin"""
"""
Mixin that enables full django app functions for a plugin
"""
class MixinMeta:
"""meta options for this mixin"""
MIXIN_NAME = 'App registration'

View File

@ -1,6 +1,9 @@
"""utility class to enable simpler imports"""
from ..builtin.integration.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin
from ..builtin.integration.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin
__all__ = [
'AppMixin', 'GlobalSettingsMixin', 'UrlsMixin', 'NavigationMixin',
'AppMixin',
'NavigationMixin',
'SettingsMixin',
'UrlsMixin',
]

View File

@ -54,7 +54,11 @@ class PluginConfig(models.Model):
# extra attributes from the registry
def mixins(self):
if self.plugin:
return self.plugin._mixinreg
else:
return {}
# functions

View File

@ -251,7 +251,7 @@ class Plugins:
if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_GLOBALSETTING'):
logger.info('Registering IntegrationPlugin global settings')
for slug, plugin in plugins:
if plugin.mixin_enabled('globalsettings'):
if plugin.mixin_enabled('settings'):
plugin_setting = plugin.globalsettingspatterns
self.mixins_globalsettings[slug] = plugin_setting

View File

@ -1,15 +1,18 @@
"""sample implementations for IntegrationPlugin"""
"""
Sample implementations for IntegrationPlugin
"""
from plugin import IntegrationPluginBase
from plugin.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin
from plugin.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
from django.conf.urls import url, include
class SampleIntegrationPlugin(AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase):
class SampleIntegrationPlugin(AppMixin, SettingsMixin, UrlsMixin, NavigationMixin, IntegrationPluginBase):
"""
An full integration plugin
A full integration plugin example
"""
PLUGIN_NAME = "SampleIntegrationPlugin"

View File

@ -8,7 +8,7 @@ from django.contrib.auth import get_user_model
from datetime import datetime
from plugin import IntegrationPluginBase
from plugin.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin
from plugin.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin
from plugin.urls import PLUGIN_BASE
@ -20,19 +20,19 @@ class BaseMixinDefinition:
self.assertEqual(self.mixin.registered_mixins[0]['human_name'], self.MIXIN_HUMAN_NAME)
class GlobalSettingsMixinTest(BaseMixinDefinition, TestCase):
MIXIN_HUMAN_NAME = 'Global settings'
MIXIN_NAME = 'globalsettings'
class SettingsMixinTest(BaseMixinDefinition, TestCase):
MIXIN_HUMAN_NAME = 'Settings'
MIXIN_NAME = 'settings'
MIXIN_ENABLE_CHECK = 'has_globalsettings'
TEST_SETTINGS = {'SETTING1': {'default': '123', }}
def setUp(self):
class SettingsCls(GlobalSettingsMixin, IntegrationPluginBase):
GLOBALSETTINGS = self.TEST_SETTINGS
class SettingsCls(SettingsMixin, IntegrationPluginBase):
SETTINGS = self.TEST_SETTINGS
self.mixin = SettingsCls()
class NoSettingsCls(GlobalSettingsMixin, IntegrationPluginBase):
class NoSettingsCls(SettingsMixin, IntegrationPluginBase):
pass
self.mixin_nothing = NoSettingsCls()

View File

@ -18,7 +18,7 @@
<tr>
<td>{{key}}</td>
<td>{{entry.1}}</td>
<td><a class="btn btn-primary btn-small" href="/{{ base }}{{entry.1}}" target="_blank">{% trans 'open in new tab' %}</a></td>
<td><a class="btn btn-primary btn-small" href="/{{ base }}{{entry.1}}" target="_blank">{% trans 'Open in new tab' %}</a></td>
</tr>
{% endif %}{% endfor %}
</tbody>

View File

@ -70,7 +70,7 @@
{% if mixin_list %}
{% for mixin in mixin_list %}
<a class='sidebar-selector' id='select-plugin-{{plugin_key}}' data-bs-parent="#sidebar">
<span class='badge bg-dark badge-right'>{% blocktrans with name=mixin.human_name %}has {{name}}{% endblocktrans %}</span>
<span class='badge bg-dark badge-right'>{{ mixin.human_name }}</span>
</a>
{% endfor %}
{% endif %}

View File

@ -67,7 +67,10 @@
</div>
{% if plugin.is_package == False %}
<p>{% trans 'The code information is pulled from the latest git commit for this plugin. It might not reflect official version numbers or information but the actual code running.' %}</p>
<div class='alert alert-block alert-info'>
{% trans 'The code information is pulled from the latest git commit for this plugin. It might not reflect official version numbers or information but the actual code running.' %}
</div>
{% endif %}
</div>
<div class="col">

View File

@ -59,6 +59,7 @@ RUN apk -U upgrade
# Install required system packages
RUN apk add --no-cache git make bash \
gcc libgcc g++ libstdc++ \
gnupg \
libjpeg-turbo libjpeg-turbo-dev jpeg jpeg-dev \
libffi libffi-dev \
zlib zlib-dev \