From a55a68d629fbf7d015318712dee77e5707e6db49 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Wed, 25 May 2022 22:30:33 +0200 Subject: [PATCH] Update metadata Closes #282 --- docs/extend/how_to_plugin.md | 8 ++++---- docs/extend/plugins.md | 7 ++++--- docs/extend/plugins/event.md | 8 ++++---- docs/extend/plugins/label.md | 8 ++++---- docs/extend/plugins/navigation.md | 4 ++-- docs/extend/plugins/schedule.md | 6 +++--- docs/extend/plugins/settings.md | 4 ++-- docs/extend/plugins/urls.md | 4 ++-- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/extend/how_to_plugin.md b/docs/extend/how_to_plugin.md index d2a9fc8..d757bcf 100644 --- a/docs/extend/how_to_plugin.md +++ b/docs/extend/how_to_plugin.md @@ -38,7 +38,7 @@ If you want to make your life easier, try to follow these guidelines; break wher - do not use internal functions - if a functions name starts with `_` it is internal and might change at any time - keep you imports clean - the APIs for plugins and mixins are young and evolving. Use ``` -from plugin import IntegrationPluginBase, registry +from plugin import InvenTreePlugin, registry from plugin.mixins import APICallMixin, SettingsMixin, ScheduleMixin, BarcodeMixin ``` - deliver as a package - pip is great for dependency management and pypi can serve as a transparent and reliable delivery infrastructure @@ -52,16 +52,16 @@ This example adds a new action under `/api/action/sample` using the ActionMixin. ``` py # -*- coding: utf-8 -*- """sample implementation for ActionPlugin""" -from plugin import IntegrationPluginBase +from plugin import InvenTreePlugin from plugin.mixins import ActionMixin -class SampleActionPlugin(ActionMixin, IntegrationPluginBase): +class SampleActionPlugin(ActionMixin, InvenTreePlugin): """ Use docstrings for everything... pls """ - PLUGIN_NAME = "SampleActionPlugin" + NAME = "SampleActionPlugin" ACTION_NAME = "sample" # metadata diff --git a/docs/extend/plugins.md b/docs/extend/plugins.md index 9ff6134..32c65f6 100644 --- a/docs/extend/plugins.md +++ b/docs/extend/plugins.md @@ -22,15 +22,16 @@ Note: Plugins are discovered and loaded only when the server is started. ### Plugin Base Class -Custom plugins must inherit from the [IntegrationPluginBase class](https://github.com/inventree/InvenTree/blob/2d1776a151721d65d0ae007049d358085b2fcfd5/InvenTree/plugin/plugin.py#L204). Any plugins installed via the methods outlined above will be "discovered" when the InvenTree server launches. +Custom plugins must inherit from the [InvenTreePlugin class](https://github.com/inventree/InvenTree/blob/2d1776a151721d65d0ae007049d358085b2fcfd5/InvenTree/plugin/plugin.py#L204). Any plugins installed via the methods outlined above will be "discovered" when the InvenTree server launches. ### Plugin Options Some metadata options can be defined as constants in the plugins class ``` python -PLUGIN_SLUG = None # Used in URLs, setting-names etc. when a unique slug as a reference is needed -> the plugin name is used if not set -PLUGIN_TITLE = None # A nice human friendly name for the plugin -> used in titles, as plugin name etc. +NAME = '' # Used as a general reference to the plugin +SLUG = None # Used in URLs, setting-names etc. when a unique slug as a reference is needed -> the plugin name is used if not set +TITLE = None # A nice human friendly name for the plugin -> used in titles, as plugin name etc. AUTHOR = None # Author of the plugin, git commit information is used if not present PUBLISH_DATE = None # Publishing date of the plugin, git commit information is used if not present diff --git a/docs/extend/plugins/event.md b/docs/extend/plugins/event.md index 5dbf92d..61a1852 100644 --- a/docs/extend/plugins/event.md +++ b/docs/extend/plugins/event.md @@ -11,7 +11,7 @@ When a certain (server-side) event occurs, the background worker passes the even Implementing classes must provide a `process_event` function: ```python -class EventPlugin(EventMixin, IntegrationPluginBase): +class EventPlugin(EventMixin, InvenTreePlugin): """ A simple example plugin which responds to events on the InvenTree server. @@ -19,9 +19,9 @@ class EventPlugin(EventMixin, IntegrationPluginBase): A more complex plugin could respond to specific events however it wanted. """ - PLUGIN_NAME = "EventPlugin" - PLUGIN_SLUG = "event" - PLUGIN_TITLE = "Triggered Events" + NAME = "EventPlugin" + SLUG = "event" + TITLE = "Triggered Events" def process_event(self, event, *args, **kwargs): print(f"Processing triggered event: '{event}'") diff --git a/docs/extend/plugins/label.md b/docs/extend/plugins/label.md index 1a8a6a5..ecbacbd 100644 --- a/docs/extend/plugins/label.md +++ b/docs/extend/plugins/label.md @@ -27,16 +27,16 @@ Plugins which implement the `LabelPrintingMixin` mixin class must provide a `pri ```python from dummy_printer import printer_backend -class MyLabelPrinter(LabelPrintingMixin, IntegrationPluginBase): +class MyLabelPrinter(LabelPrintingMixin, InvenTreePlugin): """ A simple example plugin which provides support for a dummy printer. A more complex plugin would communicate with an actual printer! """ - PLUGIN_NAME = "MyLabelPrinter" - PLUGIN_SLUG = "mylabel" - PLUGIN_TITLE = "A dummy printer" + NAME = "MyLabelPrinter" + SLUG = "mylabel" + TITLE = "A dummy printer" def print_label(self, label, **kwargs): """ diff --git a/docs/extend/plugins/navigation.md b/docs/extend/plugins/navigation.md index 86e3ce4..36c4a6f 100644 --- a/docs/extend/plugins/navigation.md +++ b/docs/extend/plugins/navigation.md @@ -8,9 +8,9 @@ Use the class constant `NAVIGATION` for a array of links that should be added to The array must contain at least one dict that at least define a name and a link for each element. The link must be formatted for a URL pattern name lookup - links to external sites are not possible directly. The optional icon must be a class reference to an icon (InvenTree ships with fontawesome 4 by default). ``` python -class MyNavigationPlugin(NavigationMixin, IntegrationPluginBase): +class MyNavigationPlugin(NavigationMixin, InvenTreePlugin): - PLUGIN_NAME = "NavigationPlugin" + NAME = "NavigationPlugin" NAVIGATION = [ {'name': 'SampleIntegration', 'link': 'plugin:sample:hi', 'icon': 'fas fa-box'}, diff --git a/docs/extend/plugins/schedule.md b/docs/extend/plugins/schedule.md index c4a74e5..a680a15 100644 --- a/docs/extend/plugins/schedule.md +++ b/docs/extend/plugins/schedule.md @@ -16,13 +16,13 @@ The ScheduleMixin class provides a plugin with the ability to call functions at An example of a plugin which supports scheduled tasks: ```python -class ScheduledTaskPlugin(ScheduleMixin, SettingsMixin, IntegrationPluginBase): +class ScheduledTaskPlugin(ScheduleMixin, SettingsMixin, InvenTreePlugin): """ Sample plugin which runs a scheduled task, and provides user configuration. """ - PLUGIN_NAME = "Scheduled Tasks" - PLUGIN_SLUG = 'schedule' + NAME = "Scheduled Tasks" + SLUG = 'schedule' SCHEDULED_TASKS = { 'global': { diff --git a/docs/extend/plugins/settings.md b/docs/extend/plugins/settings.md index 484ed81..8309b77 100644 --- a/docs/extend/plugins/settings.md +++ b/docs/extend/plugins/settings.md @@ -15,9 +15,9 @@ The dict must be formatted similar to the following sample. Take a look at the s ``` python -class PluginWithSettings(SettingsMixin, IntegrationPluginBase): +class PluginWithSettings(SettingsMixin, InvenTreePlugin): - PLUGIN_NAME = "PluginWithSettings" + NAME = "PluginWithSettings" SETTINGS = { 'API_ENABLE': { diff --git a/docs/extend/plugins/urls.md b/docs/extend/plugins/urls.md index 1892a94..e242e7a 100644 --- a/docs/extend/plugins/urls.md +++ b/docs/extend/plugins/urls.md @@ -9,9 +9,9 @@ Use the class constant `URLS` for a array of URLs that should be added to InvenT The array has to contain valid URL patterns as defined in the [django documentation](https://docs.djangoproject.com/en/stable/topics/http/urls/). ``` python -class MyUrlsPlugin(URLsMixin, IntegrationPluginBase): +class MyUrlsPlugin(URLsMixin, InvenTreePlugin): - PLUGIN_NAME = "UrlsMixin" + NAME = "UrlsMixin" URLS = [ url(r'increase/(?P\d+)/(?P\d+)/', self.view_increase, name='increase-level'),