mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-10-24 00:08:57 +03:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f024e4feb5 | ||
|
|
92cb5e8b1f |
@@ -136,6 +136,15 @@ class LocalizedValue(dict):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def is_empty(self) -> bool:
|
||||||
|
"""Gets whether all the languages contain the default value."""
|
||||||
|
|
||||||
|
for lang_code, _ in settings.LANGUAGES:
|
||||||
|
if self.get(lang_code) != self.default_value:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""Gets the value in the current language or falls back to the next
|
"""Gets the value in the current language or falls back to the next
|
||||||
language if there's no value in the current language."""
|
language if there's no value in the current language."""
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -36,7 +36,7 @@ with open(
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="django-localized-fields",
|
name="django-localized-fields",
|
||||||
version="6.3",
|
version="6.4",
|
||||||
packages=find_packages(exclude=["tests"]),
|
packages=find_packages(exclude=["tests"]),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
license="MIT License",
|
license="MIT License",
|
||||||
|
|||||||
@@ -38,6 +38,17 @@ class LocalizedValueTestCase(TestCase):
|
|||||||
for lang_code, _ in settings.LANGUAGES:
|
for lang_code, _ in settings.LANGUAGES:
|
||||||
assert getattr(value, lang_code) is None
|
assert getattr(value, lang_code) is None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def test_is_empty():
|
||||||
|
"""Tests whether a newly constructed :see:LocalizedValue without any
|
||||||
|
content is considered "empty"."""
|
||||||
|
|
||||||
|
value = LocalizedValue()
|
||||||
|
assert value.is_empty()
|
||||||
|
|
||||||
|
value.set(settings.LANGUAGE_CODE, "my value")
|
||||||
|
assert not value.is_empty()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def test_init_array():
|
def test_init_array():
|
||||||
"""Tests whether the __init__ function of :see:LocalizedValue properly
|
"""Tests whether the __init__ function of :see:LocalizedValue properly
|
||||||
|
|||||||
Reference in New Issue
Block a user