2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +00:00

Adds API endpoints for viewing and updating plugin settings

A lot of code updates / refactoring here to get this to work as expected
This commit is contained in:
Oliver
2022-01-02 14:12:34 +11:00
parent f3bfe6e7ca
commit dc9e25ebad
23 changed files with 250 additions and 80 deletions

View File

@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
"""Base Class for InvenTree plugins"""
"""
Base Class for InvenTree plugins
"""
from django.db.utils import OperationalError, ProgrammingError
from django.utils.text import slugify
@ -10,6 +12,9 @@ class InvenTreePlugin():
Base class for a plugin
"""
def __init__(self):
pass
# Override the plugin name for each concrete plugin instance
PLUGIN_NAME = ''
@ -36,5 +41,22 @@ class InvenTreePlugin():
return self.PLUGIN_TITLE
def __init__(self):
pass
def plugin_config(self, raise_error=False):
"""
Return the PluginConfig object associated with this plugin
"""
try:
import plugin.models
cfg, _ = plugin.models.PluginConfig.objects.get_or_create(
key=self.plugin_slug(),
name=self.plugin_name(),
)
except (OperationalError, ProgrammingError) as error:
cfg = None
if raise_error:
raise error
return cfg