mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 03:55:41 +00:00
fix docstrings 6
This commit is contained in:
@ -1,6 +1,4 @@
|
|||||||
"""
|
"""Utility file to enable simper imports"""
|
||||||
Utility file to enable simper imports
|
|
||||||
"""
|
|
||||||
|
|
||||||
from .helpers import MixinImplementationError, MixinNotImplementedError
|
from .helpers import MixinImplementationError, MixinNotImplementedError
|
||||||
from .plugin import IntegrationPluginBase, InvenTreePlugin
|
from .plugin import IntegrationPluginBase, InvenTreePlugin
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
"""APIs for action plugins"""
|
"""APIs for action plugins"""
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from rest_framework import permissions
|
from rest_framework import permissions
|
||||||
@ -9,9 +10,7 @@ from plugin import registry
|
|||||||
|
|
||||||
|
|
||||||
class ActionPluginView(APIView):
|
class ActionPluginView(APIView):
|
||||||
"""
|
"""Endpoint for running custom action plugins."""
|
||||||
Endpoint for running custom action plugins.
|
|
||||||
"""
|
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
permissions.IsAuthenticated,
|
permissions.IsAuthenticated,
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
"""
|
"""Plugin mixin classes for action plugin"""
|
||||||
Plugin mixin classes for action plugin
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class ActionMixin:
|
class ActionMixin:
|
||||||
"""
|
"""Mixin that enables custom actions"""
|
||||||
Mixin that enables custom actions
|
|
||||||
"""
|
|
||||||
ACTION_NAME = ""
|
ACTION_NAME = ""
|
||||||
|
|
||||||
class MixinMeta:
|
class MixinMeta:
|
||||||
"""
|
"""Meta options for this mixin"""
|
||||||
meta options for this mixin
|
|
||||||
"""
|
|
||||||
MIXIN_NAME = 'Actions'
|
MIXIN_NAME = 'Actions'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -20,8 +16,7 @@ class ActionMixin:
|
|||||||
self.add_mixin('action', True, __class__)
|
self.add_mixin('action', True, __class__)
|
||||||
|
|
||||||
def action_name(self):
|
def action_name(self):
|
||||||
"""
|
"""Action name for this plugin.
|
||||||
Action name for this plugin.
|
|
||||||
|
|
||||||
If the ACTION_NAME parameter is empty,
|
If the ACTION_NAME parameter is empty,
|
||||||
uses the NAME instead.
|
uses the NAME instead.
|
||||||
@ -31,28 +26,22 @@ class ActionMixin:
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def perform_action(self, user=None, data=None):
|
def perform_action(self, user=None, data=None):
|
||||||
"""
|
"""Override this method to perform the action!"""
|
||||||
Override this method to perform the action!
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get_result(self, user=None, data=None):
|
def get_result(self, user=None, data=None):
|
||||||
"""
|
"""Result of the action?"""
|
||||||
Result of the action?
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Re-implement this for cutsom actions
|
# Re-implement this for cutsom actions
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_info(self, user=None, data=None):
|
def get_info(self, user=None, data=None):
|
||||||
"""
|
"""Extra info? Can be a string / dict / etc"""
|
||||||
Extra info? Can be a string / dict / etc
|
|
||||||
"""
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_response(self, user=None, data=None):
|
def get_response(self, user=None, data=None):
|
||||||
"""
|
"""Return a response.
|
||||||
Return a response. Default implementation is a simple response
|
|
||||||
which can be overridden.
|
Default implementation is a simple response which can be overridden.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"action": self.action_name(),
|
"action": self.action_name(),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
""" Unit tests for action plugins """
|
"""Unit tests for action plugins"""
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
@ -8,7 +8,8 @@ from plugin.mixins import ActionMixin
|
|||||||
|
|
||||||
|
|
||||||
class ActionMixinTests(TestCase):
|
class ActionMixinTests(TestCase):
|
||||||
""" Tests for ActionMixin """
|
"""Tests for ActionMixin"""
|
||||||
|
|
||||||
ACTION_RETURN = 'a action was performed'
|
ACTION_RETURN = 'a action was performed'
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -17,7 +18,7 @@ class ActionMixinTests(TestCase):
|
|||||||
self.plugin = SimplePlugin()
|
self.plugin = SimplePlugin()
|
||||||
|
|
||||||
class TestActionPlugin(ActionMixin, InvenTreePlugin):
|
class TestActionPlugin(ActionMixin, InvenTreePlugin):
|
||||||
"""a action plugin"""
|
"""An action plugin"""
|
||||||
ACTION_NAME = 'abc123'
|
ACTION_NAME = 'abc123'
|
||||||
|
|
||||||
def perform_action(self, user=None, data=None):
|
def perform_action(self, user=None, data=None):
|
||||||
@ -37,13 +38,13 @@ class ActionMixinTests(TestCase):
|
|||||||
self.action_name = NameActionPlugin()
|
self.action_name = NameActionPlugin()
|
||||||
|
|
||||||
def test_action_name(self):
|
def test_action_name(self):
|
||||||
"""check the name definition possibilities"""
|
"""Check the name definition possibilities"""
|
||||||
self.assertEqual(self.plugin.action_name(), '')
|
self.assertEqual(self.plugin.action_name(), '')
|
||||||
self.assertEqual(self.action_plugin.action_name(), 'abc123')
|
self.assertEqual(self.action_plugin.action_name(), 'abc123')
|
||||||
self.assertEqual(self.action_name.action_name(), 'Aplugin')
|
self.assertEqual(self.action_name.action_name(), 'Aplugin')
|
||||||
|
|
||||||
def test_function(self):
|
def test_function(self):
|
||||||
"""check functions"""
|
"""Check functions"""
|
||||||
# the class itself
|
# the class itself
|
||||||
self.assertIsNone(self.plugin.perform_action())
|
self.assertIsNone(self.plugin.perform_action())
|
||||||
self.assertEqual(self.plugin.get_result(), False)
|
self.assertEqual(self.plugin.get_result(), False)
|
||||||
@ -66,11 +67,10 @@ class ActionMixinTests(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class APITests(InvenTreeTestCase):
|
class APITests(InvenTreeTestCase):
|
||||||
""" Tests for action api """
|
"""Tests for action api"""
|
||||||
|
|
||||||
def test_post_errors(self):
|
def test_post_errors(self):
|
||||||
"""Check the possible errors with post"""
|
"""Check the possible errors with post"""
|
||||||
|
|
||||||
# Test empty request
|
# Test empty request
|
||||||
response = self.client.post('/api/action/')
|
response = self.client.post('/api/action/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
from django.urls import path, re_path, reverse
|
from django.urls import path, re_path, reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
@ -15,8 +15,7 @@ from stock.serializers import StockItemSerializer
|
|||||||
|
|
||||||
|
|
||||||
class BarcodeScan(APIView):
|
class BarcodeScan(APIView):
|
||||||
"""
|
"""Endpoint for handling generic barcode scan requests.
|
||||||
Endpoint for handling generic barcode scan requests.
|
|
||||||
|
|
||||||
Barcode data are decoded by the client application,
|
Barcode data are decoded by the client application,
|
||||||
and sent to this endpoint (as a JSON object) for validation.
|
and sent to this endpoint (as a JSON object) for validation.
|
||||||
@ -42,10 +41,7 @@ class BarcodeScan(APIView):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
"""
|
"""Respond to a barcode POST request"""
|
||||||
Respond to a barcode POST request
|
|
||||||
"""
|
|
||||||
|
|
||||||
data = request.data
|
data = request.data
|
||||||
|
|
||||||
if 'barcode' not in data:
|
if 'barcode' not in data:
|
||||||
@ -133,8 +129,7 @@ class BarcodeScan(APIView):
|
|||||||
|
|
||||||
|
|
||||||
class BarcodeAssign(APIView):
|
class BarcodeAssign(APIView):
|
||||||
"""
|
"""Endpoint for assigning a barcode to a stock item.
|
||||||
Endpoint for assigning a barcode to a stock item.
|
|
||||||
|
|
||||||
- This only works if the barcode is not already associated with an object in the database
|
- This only works if the barcode is not already associated with an object in the database
|
||||||
- If the barcode does not match an object, then the barcode hash is assigned to the StockItem
|
- If the barcode does not match an object, then the barcode hash is assigned to the StockItem
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""
|
"""Registry for loading and managing multiple plugins at run-time
|
||||||
Registry for loading and managing multiple plugins at run-time
|
|
||||||
|
|
||||||
- Holds the class and the object that contains all code to maintain plugin states
|
- Holds the class and the object that contains all code to maintain plugin states
|
||||||
- Manages setup and teardown of plugin class instances
|
- Manages setup and teardown of plugin class instances
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""
|
"""JSON serializers for plugin app"""
|
||||||
JSON serializers for plugin app
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -17,9 +15,7 @@ from plugin.models import NotificationUserSetting, PluginConfig, PluginSetting
|
|||||||
|
|
||||||
|
|
||||||
class MetadataSerializer(serializers.ModelSerializer):
|
class MetadataSerializer(serializers.ModelSerializer):
|
||||||
"""
|
"""Serializer class for model metadata API access."""
|
||||||
Serializer class for model metadata API access.
|
|
||||||
"""
|
|
||||||
|
|
||||||
metadata = serializers.JSONField(required=True)
|
metadata = serializers.JSONField(required=True)
|
||||||
|
|
||||||
@ -45,9 +41,7 @@ class MetadataSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class PluginConfigSerializer(serializers.ModelSerializer):
|
class PluginConfigSerializer(serializers.ModelSerializer):
|
||||||
"""
|
"""Serializer for a PluginConfig:"""
|
||||||
Serializer for a PluginConfig:
|
|
||||||
"""
|
|
||||||
|
|
||||||
meta = serializers.DictField(read_only=True)
|
meta = serializers.DictField(read_only=True)
|
||||||
mixins = serializers.DictField(read_only=True)
|
mixins = serializers.DictField(read_only=True)
|
||||||
@ -64,9 +58,7 @@ class PluginConfigSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class PluginConfigInstallSerializer(serializers.Serializer):
|
class PluginConfigInstallSerializer(serializers.Serializer):
|
||||||
"""
|
"""Serializer for installing a new plugin"""
|
||||||
Serializer for installing a new plugin
|
|
||||||
"""
|
|
||||||
|
|
||||||
url = serializers.CharField(
|
url = serializers.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
@ -156,9 +148,7 @@ class PluginConfigInstallSerializer(serializers.Serializer):
|
|||||||
|
|
||||||
|
|
||||||
class PluginSettingSerializer(GenericReferencedSettingSerializer):
|
class PluginSettingSerializer(GenericReferencedSettingSerializer):
|
||||||
"""
|
"""Serializer for the PluginSetting model"""
|
||||||
Serializer for the PluginSetting model
|
|
||||||
"""
|
|
||||||
|
|
||||||
MODEL = PluginSetting
|
MODEL = PluginSetting
|
||||||
EXTRA_FIELDS = [
|
EXTRA_FIELDS = [
|
||||||
@ -169,9 +159,7 @@ class PluginSettingSerializer(GenericReferencedSettingSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class NotificationUserSettingSerializer(GenericReferencedSettingSerializer):
|
class NotificationUserSettingSerializer(GenericReferencedSettingSerializer):
|
||||||
"""
|
"""Serializer for the PluginSetting model"""
|
||||||
Serializer for the PluginSetting model
|
|
||||||
"""
|
|
||||||
|
|
||||||
MODEL = NotificationUserSetting
|
MODEL = NotificationUserSetting
|
||||||
EXTRA_FIELDS = ['method', ]
|
EXTRA_FIELDS = ['method', ]
|
||||||
|
@ -8,8 +8,7 @@ from plugin import registry
|
|||||||
|
|
||||||
|
|
||||||
class PluginTemplateLoader(FilesystemLoader):
|
class PluginTemplateLoader(FilesystemLoader):
|
||||||
"""
|
"""A custom template loader which allows loading of templates from installed plugins.
|
||||||
A custom template loader which allows loading of templates from installed plugins.
|
|
||||||
|
|
||||||
Each plugin can register templates simply by providing a 'templates' directory in its root path.
|
Each plugin can register templates simply by providing a 'templates' directory in its root path.
|
||||||
|
|
||||||
|
@ -5,9 +5,7 @@ from InvenTree.api_tester import InvenTreeAPITestCase
|
|||||||
|
|
||||||
|
|
||||||
class PluginDetailAPITest(InvenTreeAPITestCase):
|
class PluginDetailAPITest(InvenTreeAPITestCase):
|
||||||
"""
|
"""Tests the plugin API endpoints"""
|
||||||
Tests the plugin API endpoints
|
|
||||||
"""
|
|
||||||
|
|
||||||
roles = [
|
roles = [
|
||||||
'admin.add',
|
'admin.add',
|
||||||
@ -24,9 +22,7 @@ class PluginDetailAPITest(InvenTreeAPITestCase):
|
|||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
def test_plugin_install(self):
|
def test_plugin_install(self):
|
||||||
"""
|
"""Test the plugin install command"""
|
||||||
Test the plugin install command
|
|
||||||
"""
|
|
||||||
url = reverse('api-plugin-install')
|
url = reverse('api-plugin-install')
|
||||||
|
|
||||||
# valid - Pypi
|
# valid - Pypi
|
||||||
@ -73,9 +69,7 @@ class PluginDetailAPITest(InvenTreeAPITestCase):
|
|||||||
self.assertEqual(data['confirm'][0].title().upper(), 'Installation not confirmed'.upper())
|
self.assertEqual(data['confirm'][0].title().upper(), 'Installation not confirmed'.upper())
|
||||||
|
|
||||||
def test_admin_action(self):
|
def test_admin_action(self):
|
||||||
"""
|
"""Test the PluginConfig action commands"""
|
||||||
Test the PluginConfig action commands
|
|
||||||
"""
|
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
from plugin.models import PluginConfig
|
from plugin.models import PluginConfig
|
||||||
|
|
||||||
@ -132,9 +126,7 @@ class PluginDetailAPITest(InvenTreeAPITestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_model(self):
|
def test_model(self):
|
||||||
"""
|
"""Test the PluginConfig model"""
|
||||||
Test the PluginConfig model
|
|
||||||
"""
|
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
from plugin.models import PluginConfig
|
from plugin.models import PluginConfig
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""
|
"""Unit tests for plugins"""
|
||||||
Unit tests for plugins
|
|
||||||
"""
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@ -14,7 +12,7 @@ from plugin.samples.integration.sample import SampleIntegrationPlugin
|
|||||||
|
|
||||||
|
|
||||||
class PluginTagTests(TestCase):
|
class PluginTagTests(TestCase):
|
||||||
""" Tests for the plugin extras """
|
"""Tests for the plugin extras"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.sample = SampleIntegrationPlugin()
|
self.sample = SampleIntegrationPlugin()
|
||||||
@ -22,22 +20,22 @@ class PluginTagTests(TestCase):
|
|||||||
self.plugin_wrong = WrongIntegrationPlugin()
|
self.plugin_wrong = WrongIntegrationPlugin()
|
||||||
|
|
||||||
def test_tag_plugin_list(self):
|
def test_tag_plugin_list(self):
|
||||||
"""test that all plugins are listed"""
|
"""Test that all plugins are listed"""
|
||||||
self.assertEqual(plugin_tags.plugin_list(), registry.plugins)
|
self.assertEqual(plugin_tags.plugin_list(), registry.plugins)
|
||||||
|
|
||||||
def test_tag_incative_plugin_list(self):
|
def test_tag_incative_plugin_list(self):
|
||||||
"""test that all inactive plugins are listed"""
|
"""Test that all inactive plugins are listed"""
|
||||||
self.assertEqual(plugin_tags.inactive_plugin_list(), registry.plugins_inactive)
|
self.assertEqual(plugin_tags.inactive_plugin_list(), registry.plugins_inactive)
|
||||||
|
|
||||||
def test_tag_plugin_settings(self):
|
def test_tag_plugin_settings(self):
|
||||||
"""check all plugins are listed"""
|
"""Check all plugins are listed"""
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
plugin_tags.plugin_settings(self.sample),
|
plugin_tags.plugin_settings(self.sample),
|
||||||
registry.mixins_settings.get(self.sample)
|
registry.mixins_settings.get(self.sample)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_tag_mixin_enabled(self):
|
def test_tag_mixin_enabled(self):
|
||||||
"""check that mixin enabled functions work"""
|
"""Check that mixin enabled functions work"""
|
||||||
key = 'urls'
|
key = 'urls'
|
||||||
# mixin enabled
|
# mixin enabled
|
||||||
self.assertEqual(plugin_tags.mixin_enabled(self.sample, key), True)
|
self.assertEqual(plugin_tags.mixin_enabled(self.sample, key), True)
|
||||||
@ -47,19 +45,19 @@ class PluginTagTests(TestCase):
|
|||||||
self.assertEqual(plugin_tags.mixin_enabled(self.plugin_no, key), False)
|
self.assertEqual(plugin_tags.mixin_enabled(self.plugin_no, key), False)
|
||||||
|
|
||||||
def test_tag_safe_url(self):
|
def test_tag_safe_url(self):
|
||||||
"""test that the safe url tag works expected"""
|
"""Test that the safe url tag works expected"""
|
||||||
# right url
|
# right url
|
||||||
self.assertEqual(plugin_tags.safe_url('api-plugin-install'), '/api/plugin/install/')
|
self.assertEqual(plugin_tags.safe_url('api-plugin-install'), '/api/plugin/install/')
|
||||||
# wrong url
|
# wrong url
|
||||||
self.assertEqual(plugin_tags.safe_url('indexas'), None)
|
self.assertEqual(plugin_tags.safe_url('indexas'), None)
|
||||||
|
|
||||||
def test_tag_plugin_errors(self):
|
def test_tag_plugin_errors(self):
|
||||||
"""test that all errors are listed"""
|
"""Test that all errors are listed"""
|
||||||
self.assertEqual(plugin_tags.plugin_errors(), registry.errors)
|
self.assertEqual(plugin_tags.plugin_errors(), registry.errors)
|
||||||
|
|
||||||
|
|
||||||
class InvenTreePluginTests(TestCase):
|
class InvenTreePluginTests(TestCase):
|
||||||
""" Tests for InvenTreePlugin """
|
"""Tests for InvenTreePlugin"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.plugin = InvenTreePlugin()
|
self.plugin = InvenTreePlugin()
|
||||||
@ -95,21 +93,21 @@ class InvenTreePluginTests(TestCase):
|
|||||||
self.plugin_sample = SampleIntegrationPlugin()
|
self.plugin_sample = SampleIntegrationPlugin()
|
||||||
|
|
||||||
def test_basic_plugin_init(self):
|
def test_basic_plugin_init(self):
|
||||||
"""check if a basic plugin intis"""
|
"""Check if a basic plugin intis"""
|
||||||
self.assertEqual(self.plugin.NAME, '')
|
self.assertEqual(self.plugin.NAME, '')
|
||||||
self.assertEqual(self.plugin.plugin_name(), '')
|
self.assertEqual(self.plugin.plugin_name(), '')
|
||||||
|
|
||||||
def test_basic_plugin_name(self):
|
def test_basic_plugin_name(self):
|
||||||
"""check if the name of a basic plugin can be set"""
|
"""Check if the name of a basic plugin can be set"""
|
||||||
self.assertEqual(self.named_plugin.NAME, 'abc123')
|
self.assertEqual(self.named_plugin.NAME, 'abc123')
|
||||||
self.assertEqual(self.named_plugin.plugin_name(), 'abc123')
|
self.assertEqual(self.named_plugin.plugin_name(), 'abc123')
|
||||||
|
|
||||||
def test_basic_is_active(self):
|
def test_basic_is_active(self):
|
||||||
"""check if a basic plugin is active"""
|
"""Check if a basic plugin is active"""
|
||||||
self.assertEqual(self.plugin.is_active(), False)
|
self.assertEqual(self.plugin.is_active(), False)
|
||||||
|
|
||||||
def test_action_name(self):
|
def test_action_name(self):
|
||||||
"""check the name definition possibilities"""
|
"""Check the name definition possibilities"""
|
||||||
# plugin_name
|
# plugin_name
|
||||||
self.assertEqual(self.plugin.plugin_name(), '')
|
self.assertEqual(self.plugin.plugin_name(), '')
|
||||||
self.assertEqual(self.plugin_simple.plugin_name(), 'SimplePlugin')
|
self.assertEqual(self.plugin_simple.plugin_name(), 'SimplePlugin')
|
||||||
@ -157,7 +155,6 @@ class InvenTreePluginTests(TestCase):
|
|||||||
|
|
||||||
def test_depreciation(self):
|
def test_depreciation(self):
|
||||||
"""Check if depreciations raise as expected"""
|
"""Check if depreciations raise as expected"""
|
||||||
|
|
||||||
# check deprecation warning is firing
|
# check deprecation warning is firing
|
||||||
with self.assertWarns(DeprecationWarning):
|
with self.assertWarns(DeprecationWarning):
|
||||||
self.assertEqual(self.plugin_old.slug, 'old')
|
self.assertEqual(self.plugin_old.slug, 'old')
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""
|
"""URL lookup for plugin app"""
|
||||||
URL lookup for plugin app
|
|
||||||
"""
|
|
||||||
|
|
||||||
from django.urls import include, re_path
|
from django.urls import include, re_path
|
||||||
|
|
||||||
@ -10,10 +8,7 @@ PLUGIN_BASE = 'plugin' # Constant for links
|
|||||||
|
|
||||||
|
|
||||||
def get_plugin_urls():
|
def get_plugin_urls():
|
||||||
"""
|
"""Returns a urlpattern that can be integrated into the global urls"""
|
||||||
Returns a urlpattern that can be integrated into the global urls
|
|
||||||
"""
|
|
||||||
|
|
||||||
urls = []
|
urls = []
|
||||||
|
|
||||||
for plugin in registry.plugins.values():
|
for plugin in registry.plugins.values():
|
||||||
|
@ -13,19 +13,14 @@ logger = logging.getLogger('inventree')
|
|||||||
|
|
||||||
|
|
||||||
class InvenTreePluginViewMixin:
|
class InvenTreePluginViewMixin:
|
||||||
"""
|
"""Custom view mixin which adds context data to the view,
|
||||||
Custom view mixin which adds context data to the view,
|
|
||||||
based on loaded plugins.
|
based on loaded plugins.
|
||||||
|
|
||||||
This allows rendered pages to be augmented by loaded plugins.
|
This allows rendered pages to be augmented by loaded plugins.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_plugin_panels(self, ctx):
|
def get_plugin_panels(self, ctx):
|
||||||
"""
|
"""Return a list of extra 'plugin panels' associated with this view"""
|
||||||
Return a list of extra 'plugin panels' associated with this view
|
|
||||||
"""
|
|
||||||
|
|
||||||
panels = []
|
panels = []
|
||||||
|
|
||||||
for plug in registry.with_mixin('panel', active=True):
|
for plug in registry.with_mixin('panel', active=True):
|
||||||
@ -50,10 +45,7 @@ class InvenTreePluginViewMixin:
|
|||||||
return panels
|
return panels
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
"""
|
"""Add plugin context data to the view"""
|
||||||
Add plugin context data to the view
|
|
||||||
"""
|
|
||||||
|
|
||||||
ctx = super().get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
if settings.PLUGINS_ENABLED:
|
if settings.PLUGINS_ENABLED:
|
||||||
|
Reference in New Issue
Block a user