mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
adding API endpoints for plugins
This commit is contained in:
parent
958b47e58b
commit
b0142de421
@ -28,6 +28,7 @@ from build.api import build_api_urls
|
||||
from order.api import order_api_urls
|
||||
from label.api import label_api_urls
|
||||
from report.api import report_api_urls
|
||||
from plugin.api import plugin_api_urls
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
@ -63,6 +64,7 @@ apipatterns = [
|
||||
url(r'^order/', include(order_api_urls)),
|
||||
url(r'^label/', include(label_api_urls)),
|
||||
url(r'^report/', include(report_api_urls)),
|
||||
url(r'^plugin/', include(plugin_api_urls)),
|
||||
|
||||
# User URLs
|
||||
url(r'^user/', include(user_urls)),
|
||||
|
45
InvenTree/plugin/api.py
Normal file
45
InvenTree/plugin/api.py
Normal file
@ -0,0 +1,45 @@
|
||||
"""
|
||||
JSON API for the plugin app
|
||||
"""
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from rest_framework import generics
|
||||
|
||||
from plugin.models import PluginConfig
|
||||
import plugin.serializers as PluginSerializers
|
||||
|
||||
|
||||
class PluginList(generics.ListAPIView):
|
||||
""" API endpoint for list of PluginConfig objects
|
||||
|
||||
- GET: Return a list of all PluginConfig objects
|
||||
"""
|
||||
|
||||
serializer_class = PluginSerializers.PluginConfigSerializer
|
||||
queryset = PluginConfig.objects.all()
|
||||
|
||||
ordering_fields = [
|
||||
'key',
|
||||
'name',
|
||||
'active',
|
||||
]
|
||||
|
||||
ordering = [
|
||||
'key',
|
||||
]
|
||||
|
||||
search_fields = [
|
||||
'key',
|
||||
'name',
|
||||
]
|
||||
|
||||
|
||||
plugin_api_urls = [
|
||||
# Anything else
|
||||
url(r'^.*$', PluginList.as_view(), name='api-plugin-list'),
|
||||
]
|
@ -8,6 +8,7 @@ from __future__ import unicode_literals
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.db import models
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class PluginConfig(models.Model):
|
||||
@ -51,11 +52,25 @@ class PluginConfig(models.Model):
|
||||
name += '(not active)'
|
||||
return name
|
||||
|
||||
# functions
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""override to set original state of"""
|
||||
super().__init__(*args, **kwargs)
|
||||
self.__org_active = self.active
|
||||
|
||||
# append settings from registry
|
||||
self.plugin = settings.INTEGRATION_PLUGINS.get(self.key, None)
|
||||
|
||||
def get_plugin_meta(name):
|
||||
if self.plugin:
|
||||
return str(getattr(self.plugin, name, None))
|
||||
return None
|
||||
|
||||
self.meta = {key: get_plugin_meta(key) for key in ['slug', 'human_name', 'description', 'author', \
|
||||
'pub_date', 'version', 'website', 'license', 'package_path', 'settings_url', ]}
|
||||
|
||||
|
||||
def save(self, force_insert=False, force_update=False, *args, **kwargs):
|
||||
"""extend save method to reload plugins if the 'active' status changes"""
|
||||
reload = kwargs.pop('no_reload', False) # check if no_reload flag is set
|
||||
|
28
InvenTree/plugin/serializers.py
Normal file
28
InvenTree/plugin/serializers.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""
|
||||
JSON serializers for Stock app
|
||||
"""
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
from plugin.models import PluginConfig
|
||||
|
||||
|
||||
class PluginConfigSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for a PluginConfig:
|
||||
"""
|
||||
|
||||
meta = serializers.DictField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = PluginConfig
|
||||
fields = [
|
||||
'key',
|
||||
'name',
|
||||
'active',
|
||||
'meta',
|
||||
]
|
Loading…
Reference in New Issue
Block a user