mirror of
https://github.com/inventree/inventree-docs.git
synced 2025-04-27 05:06:43 +00:00
Left some words on the settings mixin (#442)
* started python API reference guide * Added test to the API reference guide * Added Price break * added context variables to the build section * Cleand up build section and added new example * Fine tuning * fixed picture * removed unfinished python reference guide * Added allocated_stock to the build rreport * Added contect variables for user model * Added link to user in build.md * Fixed misunderstanding of can_complete * Added context variables for Suppliers * Fixed typos * Added example for a warehouse pick list * Added path trick to the picklist example * Corrected typo * Added context variables for stock locations * changed some wordings * Added a remark for get_setting * Added example on int validator
This commit is contained in:
parent
4217bef85a
commit
90d842d6f9
@ -11,7 +11,7 @@ The *SettingsMixin* allows the plugin to save and load persistent settings to th
|
||||
|
||||
Use the class constant `SETTINGS` for a dict of settings that should be added as global database settings.
|
||||
|
||||
The dict must be formatted similar to the following sample. Take a look at the settings defined in `InvenTree.common.models.InvenTreeSetting` for all possible parameters.
|
||||
The dict must be formatted similar to the following sample that shows how to use validator choices and default. Take a look at the settings defined in `InvenTree.common.models.InvenTreeSetting` for all possible parameters.
|
||||
|
||||
|
||||
``` python
|
||||
@ -36,13 +36,31 @@ class PluginWithSettings(SettingsMixin, InvenTreePlugin):
|
||||
'description': _('Base URL for remote server'),
|
||||
'default': 'http://remote.url/api',
|
||||
},
|
||||
'CONNECTION': {
|
||||
'name': _('Printer Interface'),
|
||||
'description': _('Select local or network printer'),
|
||||
'choices': [('local','Local printer e.g. USB'),('network','Network printer with IP address')],
|
||||
'default': 'local',
|
||||
},
|
||||
'NUMBER': {
|
||||
'name': _('A Name'),
|
||||
'description': _('Descripe me here'),
|
||||
'default': 6,
|
||||
'validator': [
|
||||
int,
|
||||
MinValueValidator(2),
|
||||
MaxValueValidator(25)
|
||||
]
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
This mixin defines the helper functions `plugin.get_setting` and `plugin.set_seting` to access all plugin specific settings:
|
||||
|
||||
```python
|
||||
api_url = self.get_setting('API_URL')
|
||||
api_url = self.get_setting('API_URL', cache = False)
|
||||
self.set_setting('API_URL', 'some value')
|
||||
```
|
||||
`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` ist the default that means the value is taken directly from the database.
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user