2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-12 10:05:39 +00:00

Added required attribute to settings/plugins, refactor: allValues (#5224)

* Added required attribute to settings/plugins, refactor: allValues

- added 'required' attribute to InvenTreeBaseSetting
- added 'check_all_settings'
- added 'all_settings' to get a list of all defined settings
- refactored 'allValues' to use new 'all_settings' function
- added docs for new 'check_setting' function on plugin SettingsMixin

* Fix typing to be compatible with python 3.9

* trigger: ci

* Fixed **kwargs bug and added tests
This commit is contained in:
Lukas
2023-07-12 00:19:19 +02:00
committed by GitHub
parent b3dcc28bd9
commit ee274739a6
6 changed files with 142 additions and 26 deletions

View File

@ -35,6 +35,7 @@ class PluginWithSettings(SettingsMixin, InvenTreePlugin):
'name': 'API Key',
'description': 'Security key for accessing remote API',
'default': '',
'required': True,
},
'API_URL': {
'name': _('API URL'),
@ -71,10 +72,11 @@ class PluginWithSettings(SettingsMixin, InvenTreePlugin):
!!! tip "Hidden Settings"
Plugin settings can be hidden from the settings page by marking them as 'hidden'
This mixin defines the helper functions `plugin.get_setting` and `plugin.set_setting` to access all plugin specific settings:
This mixin defines the helper functions `plugin.get_setting`, `plugin.set_setting` and `plugin.check_settings` to access all plugin specific settings. The `plugin.check_settings` function can be used to check if all settings marked with `'required': True` are defined and not equal to `''`. Note that these methods cannot be used in the `__init__` function of your plugin.
```python
api_url = self.get_setting('API_URL', cache = False)
self.set_setting('API_URL', 'some value')
is_valid, missing_settings = self.check_settings()
```
`get_setting` has an additional parameter which lets control if the value is taken directly from the database or from the cache. If it is left away `False` is the default that means the value is taken directly from the database.