DCS - the most advanced admin editable setting
Project description
[DCS] Split By First Line
The components is part of Content Settings Family and allows you to put a multiple values in one setting using a splitter defined in the first line of the
Overview
SplitByFirstLine
Split a given text value into multiple values using a splitter that is defined inside of the value. The result of splitting will be converted using type inside of the split_type attribute. Each value can be given under the same name suffix (but lowercased), but also the returned value can be chosen by the function split_default_chooser attribute. The first line will be used as a splitter if the value from the split_default_key attribute is in this line. It may sound confusing, but let me show you an example:
from content_settings.types.array import SplitByFirstLine
MY_VAR = SplitByFirstLine(
split_default_key="MAIN",
split_type=SimpleDecimal()
)
# now the variable will work as simple Decimal, with the extra suffix __main that returns the same value
# but if you update the value in admin to:
"""=== MAIN ===
10.67
=== SECOND ===
4.12
"""
# your variable will work a bit different
content_settings.MY_VAR == Decimal("10.67")
content_settings.MY_VAR__main == Decimal("10.67")
content_settings.MY_VAR__second == Decimal("4.12")
# the first line in the value === MAIN === defines the splitter rule, which means the following value will work the same
"""!!! MAIN !!!
10.67
!!! SECOND !!!
4.12
"""
It has a wide variety of attributes:
- split_type - the type which will be used for each value. You can use a dict to set a specific type for each key
- split_default_key - the key which will be used for the first line
- split_default_chooser - the function which will be used for choosing default value
- split_not_found - what should be done if the required key is not found.
NOT_FOUND.DEFAULT- return default value,NOT_FOUND.KEY_ERRORraise an exception andNOT_FOUND.VALUEreturn value from split_not_found_value - split_key_validator - a function that validates a key. You can use a function
split_validator_infor the validator value - split_key_validator_failed - two passible values
SPLIT_FAIL.IGNORE(default) andSPLIT_FAIL.RAISE. What should the system do if validation is failed.SPLIT_FAIL.IGNORE- just use the line with an invalid key as a value for the previous key.SPLIT_FAIL.RAISE- raiseValidationError
SplitTranslation
same as SplitByFirstLine but the default value will be chosen based on current django translation django.utils.translation.get_language
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dcs_split_by_first_line-0.1.1.tar.gz.
File metadata
- Download URL: dcs_split_by_first_line-0.1.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.11.3 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b038af9f2db63a7af6c7a407139f5c7460fee13c947c63f5f1dd72962b3b14a7
|
|
| MD5 |
c5abe6fdc91bfb0db88c2c0f48e74e5b
|
|
| BLAKE2b-256 |
6ed0d1215ee8702488ae9bf1d37651474cea1c4f3526cb769ffb59c95c1ba89b
|
File details
Details for the file dcs_split_by_first_line-0.1.1-py3-none-any.whl.
File metadata
- Download URL: dcs_split_by_first_line-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.11.3 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d39c944edb3975d733d3063692cace32dbc02c1c4ca7ad7748db9d7290b3a353
|
|
| MD5 |
84c47dac545f7b42cbfcc303c6af7e1b
|
|
| BLAKE2b-256 |
f31e10856645bd78b061bc6739f66d52e602117422e22e640d3f1b85e91aae84
|