[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)
# [DCS] Split By First Line
The components is part of [Content Settings Family](https://django-content-settings.readthedocs.io/) 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:
```python
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_ERROR` raise an exception and `NOT_FOUND.VALUE` return value from **split_not_found_value**
- **split_key_validator** - a function that validates a key. You can use a function `split_validator_in` for the validator value
- **split_key_validator_failed** - two passible values `SPLIT_FAIL.IGNORE`(default) and `SPLIT_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` - raise `ValidationError`
### SplitTranslation
same as `SplitByFirstLine` but the default value will be chosen based on current django translation `django.utils.translation.get_language`
Raw data
{
"_id": null,
"home_page": "https://github.com/oduvan/dcs-split-by-first-line",
"name": "dcs-split-by-first-line",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "Django, settings",
"author": "oduvan",
"author_email": "a.lyabah@checkio.org",
"download_url": "https://files.pythonhosted.org/packages/6e/d0/d1215ee8702488ae9bf1d37651474cea1c4f3526cb769ffb59c95c1ba89b/dcs_split_by_first_line-0.1.1.tar.gz",
"platform": null,
"description": "[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)\n\n# [DCS] Split By First Line\n\nThe components is part of [Content Settings Family](https://django-content-settings.readthedocs.io/) and allows you to put a multiple values in one setting using a splitter defined in the first line of the \n\n## Overview\n\n### SplitByFirstLine\n\nSplit 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:\n\n```python\nfrom content_settings.types.array import SplitByFirstLine\n\nMY_VAR = SplitByFirstLine(\n split_default_key=\"MAIN\",\n split_type=SimpleDecimal()\n)\n\n# now the variable will work as simple Decimal, with the extra suffix __main that returns the same value\n# but if you update the value in admin to:\n\"\"\"=== MAIN ===\n10.67\n=== SECOND ===\n4.12\n\"\"\"\n# your variable will work a bit different\ncontent_settings.MY_VAR == Decimal(\"10.67\")\ncontent_settings.MY_VAR__main == Decimal(\"10.67\")\ncontent_settings.MY_VAR__second == Decimal(\"4.12\")\n\n# the first line in the value === MAIN === defines the splitter rule, which means the following value will work the same\n\"\"\"!!! MAIN !!!\n10.67\n!!! SECOND !!!\n4.12\n\"\"\"\n```\n\nIt has a wide variety of attributes:\n\n- **split_type** - the type which will be used for each value. You can use a dict to set a specific type for each key\n- **split_default_key** - the key which will be used for the first line\n- **split_default_chooser** - the function which will be used for choosing default value\n- **split_not_found** - what should be done if the required key is not found. `NOT_FOUND.DEFAULT` - return default value, `NOT_FOUND.KEY_ERROR` raise an exception and `NOT_FOUND.VALUE` return value from **split_not_found_value**\n- **split_key_validator** - a function that validates a key. You can use a function `split_validator_in` for the validator value\n- **split_key_validator_failed** - two passible values `SPLIT_FAIL.IGNORE`(default) and `SPLIT_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` - raise `ValidationError`\n\n### SplitTranslation\n\nsame as `SplitByFirstLine` but the default value will be chosen based on current django translation `django.utils.translation.get_language`\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "DCS - the most advanced admin editable setting",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/oduvan/dcs-split-by-first-line",
"Repository": "https://github.com/oduvan/dcs-split-by-first-line"
},
"split_keywords": [
"django",
" settings"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f31e10856645bd78b061bc6739f66d52e602117422e22e640d3f1b85e91aae84",
"md5": "84c47dac545f7b42cbfcc303c6af7e1b",
"sha256": "d39c944edb3975d733d3063692cace32dbc02c1c4ca7ad7748db9d7290b3a353"
},
"downloads": -1,
"filename": "dcs_split_by_first_line-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "84c47dac545f7b42cbfcc303c6af7e1b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 4800,
"upload_time": "2024-09-29T14:37:30",
"upload_time_iso_8601": "2024-09-29T14:37:30.539943Z",
"url": "https://files.pythonhosted.org/packages/f3/1e/10856645bd78b061bc6739f66d52e602117422e22e640d3f1b85e91aae84/dcs_split_by_first_line-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6ed0d1215ee8702488ae9bf1d37651474cea1c4f3526cb769ffb59c95c1ba89b",
"md5": "c5abe6fdc91bfb0db88c2c0f48e74e5b",
"sha256": "b038af9f2db63a7af6c7a407139f5c7460fee13c947c63f5f1dd72962b3b14a7"
},
"downloads": -1,
"filename": "dcs_split_by_first_line-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "c5abe6fdc91bfb0db88c2c0f48e74e5b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 4329,
"upload_time": "2024-09-29T14:37:32",
"upload_time_iso_8601": "2024-09-29T14:37:32.255459Z",
"url": "https://files.pythonhosted.org/packages/6e/d0/d1215ee8702488ae9bf1d37651474cea1c4f3526cb769ffb59c95c1ba89b/dcs_split_by_first_line-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-29 14:37:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "oduvan",
"github_project": "dcs-split-by-first-line",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "dcs-split-by-first-line"
}