Skip to content

Commit

Permalink
Merge branch 'release/1.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
twidi committed Mar 14, 2016
2 parents 6efa607 + e602375 commit d704c42
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

Release *v1.0.7* - ``2016-03-13``
---------------------------------
* ensure falsy values are considered as so

Release *v1.0.6* - ``2016-02-12``
---------------------------------
* add compatibility with "display" values set using ``ugettext_lazy``
Expand Down
2 changes: 1 addition & 1 deletion extended_choices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
__author__ = 'Stephane "Twidi" Ange;'
__contact__ = "[email protected]"
__homepage__ = "https://pypi.python.org/pypi/django-extended-choices"
__version__ = "1.0.6"
__version__ = "1.0.7"
4 changes: 4 additions & 0 deletions extended_choices/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ def __reduce__(self):
)
)

def __bool__(self):
"""Use the original value to know if the value is truely of falsy"""
return bool(self.original_value)

_classes_by_type = {}


Expand Down
20 changes: 20 additions & 0 deletions extended_choices/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,26 @@ def test_django_ugettext_lazy(self):
deep_copied_choices = deepcopy(lazy_choices)
self.assertEqual(deep_copied_choices, lazy_choices)

def test_bool(self):
"""Test that having 0 or "" return `False` in a boolean context"""

bool_choices = Choices(
('', 0, ''),
('FOO', 1, 'bar'),
)

first = bool_choices.for_value(0)
second = bool_choices.for_value(1)

self.assertFalse(first.constant)
self.assertFalse(first.value)
self.assertFalse(first.display)

self.assertTrue(second.constant)
self.assertTrue(second.value)
self.assertTrue(second.display)



if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def read_relative_file(filename):

setup(
name="django-extended-choices",
version="1.0.6",
version="1.0.7",
license="BSD",
description="Little helper application to improve django choices"
"(for fields)",
Expand Down

0 comments on commit d704c42

Please sign in to comment.