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

View File

@ -1,6 +1,9 @@
"""utility class to enable simpler imports""" """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__ = [ __all__ = [
'AppMixin', 'GlobalSettingsMixin', 'UrlsMixin', 'NavigationMixin', 'AppMixin',
'NavigationMixin',
'SettingsMixin',
'UrlsMixin',
] ]

View File

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

View File

@ -251,7 +251,7 @@ class Plugins:
if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_GLOBALSETTING'): if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_GLOBALSETTING'):
logger.info('Registering IntegrationPlugin global settings') logger.info('Registering IntegrationPlugin global settings')
for slug, plugin in plugins: for slug, plugin in plugins:
if plugin.mixin_enabled('globalsettings'): if plugin.mixin_enabled('settings'):
plugin_setting = plugin.globalsettingspatterns plugin_setting = plugin.globalsettingspatterns
self.mixins_globalsettings[slug] = plugin_setting 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 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.http import HttpResponse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.conf.urls import url, include 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" PLUGIN_NAME = "SampleIntegrationPlugin"

View File

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

View File

@ -18,7 +18,7 @@
<tr> <tr>
<td>{{key}}</td> <td>{{key}}</td>
<td>{{entry.1}}</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> </tr>
{% endif %}{% endfor %} {% endif %}{% endfor %}
</tbody> </tbody>

View File

@ -70,7 +70,7 @@
{% if mixin_list %} {% if mixin_list %}
{% for mixin in mixin_list %} {% for mixin in mixin_list %}
<a class='sidebar-selector' id='select-plugin-{{plugin_key}}' data-bs-parent="#sidebar"> <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> </a>
{% endfor %} {% endfor %}
{% endif %} {% endif %}

View File

@ -67,7 +67,10 @@
</div> </div>
{% if plugin.is_package == False %} {% 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 %} {% endif %}
</div> </div>
<div class="col"> <div class="col">

View File

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