mirror of
https://github.com/inventree/inventree-docs.git
synced 2025-04-27 21:26:43 +00:00
parent
57004689a8
commit
a55a68d629
@ -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
|
||||
|
@ -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
|
||||
|
@ -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}'")
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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'},
|
||||
|
@ -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': {
|
||||
|
@ -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': {
|
||||
|
@ -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<location>\d+)/(?P<pk>\d+)/', self.view_increase, name='increase-level'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user