mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-25 11:42:54 +03:00
Added a default value for LocalizedField
This commit is contained in:
parent
15bad7b18a
commit
666335f3a7
@ -17,6 +17,9 @@ class LocalizedField(HStoreField):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initializes a new instance of :see:LocalizedValue."""
|
"""Initializes a new instance of :see:LocalizedValue."""
|
||||||
|
|
||||||
|
if 'default' not in kwargs:
|
||||||
|
kwargs['default'] = LocalizedValue()
|
||||||
|
|
||||||
super(LocalizedField, self).__init__(*args, **kwargs)
|
super(LocalizedField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -235,6 +235,33 @@ class LocalizedFieldTestCase(TestCase):
|
|||||||
assert not LocalizedField().clean(None)
|
assert not LocalizedField().clean(None)
|
||||||
assert not LocalizedField().clean(['huh'])
|
assert not LocalizedField().clean(['huh'])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def test_default_value():
|
||||||
|
"""Tests whether the default value is a :see:LocalizedValue
|
||||||
|
instance."""
|
||||||
|
|
||||||
|
field = LocalizedField()
|
||||||
|
|
||||||
|
assert field.default
|
||||||
|
assert isinstance(field.default, LocalizedValue)
|
||||||
|
|
||||||
|
for lang_code, _ in settings.LANGUAGES:
|
||||||
|
assert not field.default.get(lang_code)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def test_default_value_override():
|
||||||
|
"""Tests whether the default value of a field
|
||||||
|
can correctly be overriden."""
|
||||||
|
|
||||||
|
default_value = LocalizedValue(get_init_values())
|
||||||
|
field = LocalizedField(default=default_value)
|
||||||
|
|
||||||
|
assert field.default
|
||||||
|
assert isinstance(field.default, LocalizedValue)
|
||||||
|
|
||||||
|
for lang_code, _ in settings.LANGUAGES:
|
||||||
|
assert default_value.get(lang_code) == field.default.get(lang_code)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def test_formfield():
|
def test_formfield():
|
||||||
"""Tests whether the :see:formfield function
|
"""Tests whether the :see:formfield function
|
||||||
|
Loading…
x
Reference in New Issue
Block a user