Add LocalizedValue.is_empty()

This commit is contained in:
Swen Kooij
2021-03-22 07:47:00 +02:00
parent 5c298ef13e
commit 92cb5e8b1f
2 changed files with 20 additions and 0 deletions

View File

@@ -136,6 +136,15 @@ class LocalizedValue(dict):
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:
"""Gets the value in the current language or falls back to the next
language if there's no value in the current language."""