mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-06-27 22:03:21 +03:00
Added __eq__ operator to LocalizedValue
This commit is contained in:
parent
d529da8886
commit
b121dfc2d7
@ -76,6 +76,21 @@ class LocalizedValue:
|
|||||||
|
|
||||||
return value or ''
|
return value or ''
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
"""Compares :paramref:self to :paramref:other for
|
||||||
|
equality.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True when :paramref:self is equal to :paramref:other.
|
||||||
|
And False when they are not.
|
||||||
|
"""
|
||||||
|
|
||||||
|
for lang_code, _ in settings.LANGUAGES:
|
||||||
|
if self.get(lang_code) != other.get(lang_code):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def __repr__(self): # pragma: no cover
|
def __repr__(self): # pragma: no cover
|
||||||
"""Gets a textual representation of this object."""
|
"""Gets a textual representation of this object."""
|
||||||
|
|
||||||
|
@ -100,6 +100,19 @@ class LocalizedValueTestCase(TestCase):
|
|||||||
translation.activate(language)
|
translation.activate(language)
|
||||||
assert str(localized_value) == value
|
assert str(localized_value) == value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def test_eq():
|
||||||
|
"""Tests whether the __eq__ operator
|
||||||
|
of :see:LocalizedValue works properly."""
|
||||||
|
|
||||||
|
a = LocalizedValue({'en': 'a', 'ar': 'b'})
|
||||||
|
b = LocalizedValue({'en': 'a', 'ar': 'b'})
|
||||||
|
|
||||||
|
assert a == b
|
||||||
|
|
||||||
|
b.en = 'b'
|
||||||
|
assert a != b
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def test_str_fallback():
|
def test_str_fallback():
|
||||||
"""Tests whether the :see:LocalizedValue
|
"""Tests whether the :see:LocalizedValue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user