Skip to main content

DCS - the most advanced admin editable setting

Project description

Stand With Ukraine

[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_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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dcs_split_by_first_line-0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dcs_split_by_first_line-0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file dcs_split_by_first_line-0.1.tar.gz.

File metadata

  • Download URL: dcs_split_by_first_line-0.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

Hashes for dcs_split_by_first_line-0.1.tar.gz
Algorithm Hash digest
SHA256 2c5b8a993393a58acdf6bd9b8b42da952570a57454ea124c2c8fa637f3c8323d
MD5 866b121faaa098a95b6cca05d6775bfb
BLAKE2b-256 1c78be7bc8ee42fc08cf83f8dfe722f1a51669f95f829f928d67af8313320c69

See more details on using hashes here.

File details

Details for the file dcs_split_by_first_line-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dcs_split_by_first_line-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e55a8b52c767342d181088a4686fb89479d879ee2d2e2acce8781e6c04f7c9d
MD5 3afa13d9376b353071209f058a1cf723
BLAKE2b-256 419a09a592582eb5c31cbb25c1ffc74ef7343e3bdfcde324acc7b3e791bab6ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page