djangofloor.conf.fields
¶
Convert values from config files to Python values¶
Use these classes in your mapping provided in yourproject.iniconf:INI_MAPPING.
Check djangofloor.conf.mapping
for examples.
-
class
djangofloor.conf.fields.
BooleanConfigField
(name, setting_name, allow_none=False, **kwargs)[source]¶ Search for a boolean value in the ini file. If this value is empty and allow_none is True, then the value is None. Otherwise returns True if the provided (lower-cased) text is one of (‘1’, ‘ok’, ‘yes’, ‘true’, ‘on’)
-
class
djangofloor.conf.fields.
CharConfigField
(name, setting_name, allow_none=True, **kwargs)[source]¶ Accepts str values. If allow_none, then None replaces any empty value.
-
class
djangofloor.conf.fields.
ChoiceConfigFile
(name, setting_name, choices, help_str='', **kwargs)[source]¶ Only allow a limited set of values in the .ini file. The available values must be given as
str
.Choices must be a
dict
, mapping .ini (string) values to actual values.If an invalid value is provided by the user, then None is returned, but an error is displayed through the Django check system.
-
class
djangofloor.conf.fields.
ConfigField
(name: str, setting_name: str, from_str=<class 'str'>, to_str=<function str_or_blank>, help_str: str = None, default: object = None)[source]¶ Class that maps an option in a .ini file to a setting.
Parameters: - name – the section and the option in a .ini file (like “database.engine”)
- setting_name – the name of the setting (like “DATABASE_ENGINE”)
- from_str (callable) – any callable that takes a text value and returns an object. Default to str_or_none
- to_str (callable) – any callable that takes the Python value and that converts it to str. Default to str
- help_str – any text that can serve has help in documentation.
- default – the value that will be used in documentation. The current setting value is used if equal to None.
-
class
djangofloor.conf.fields.
FloatConfigField
(name, setting_name, allow_none=True, **kwargs)[source]¶ Accept floating-point values. If allow_none, then None replaces any empty values (other 0.0 is used).
-
class
djangofloor.conf.fields.
IntegerConfigField
(name, setting_name, allow_none=True, **kwargs)[source]¶ Accept integer values. If allow_none, then None replaces any empty values (other 0 is used).
-
class
djangofloor.conf.fields.
ListConfigField
(name, setting_name, **kwargs)[source]¶ Convert a string to a list of values, splitted with the
djangofloor.conf.fields.strip_split()
function.
-
djangofloor.conf.fields.
bool_setting
(value)[source]¶ return True if the provided (lower-cased) text is one of (‘1’, ‘ok’, ‘yes’, ‘true’, ‘on’)
-
djangofloor.conf.fields.
guess_relative_path
(value)[source]¶ Replace an absolute path by its relative path if the abspath begins by the current dir
-
djangofloor.conf.fields.
str_or_blank
(value)[source]¶ return ‘’ if the provided value is None, else return value
-
djangofloor.conf.fields.
str_or_none
(text)[source]¶ return None if the text is empty, else returns the text
-
djangofloor.conf.fields.
strip_split
(value)[source]¶ Split the value on “,” and strip spaces of the result. Remove empty values.
>>> strip_split('keyword1, keyword2 ,,keyword3') ["keyword1", "keyword2", "keyword3"]
>>> strip_split('') []
>>> strip_split(None) []
Parameters: value – Returns: a list of strings Return type: list