Skip to content

Commit

Permalink
show boolean option value to yes/no in stead of true/false (#4005)
Browse files Browse the repository at this point in the history
* show boolean option value to yes/no in stead of true/false

* remove brackets

* add unit test

Co-authored-by: Wai Law <jan@uwkm.nl>
  • Loading branch information
wlaw01 and uwkmjan committed Nov 18, 2022
1 parent 71405c5 commit 3dee0ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/oscar/apps/catalogue/abstract_models.py
Expand Up @@ -1142,6 +1142,12 @@ def _entity_as_text(self):
"""
return str(self.value)

@property
def _boolean_as_text(self):
if self.value:
return _("Yes")
return _("No")

@property
def value_as_html(self):
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/catalogue/test_attributes.py
Expand Up @@ -68,6 +68,19 @@ def test_validate_invalid_boolean_values(self):
with self.assertRaises(ValidationError):
self.attr.validate_value(1)

def test_boolean_value_as_text_true(self):
product = factories.ProductFactory()
self.attr.save_value(product, True)
attr_val = product.attribute_values.get(attribute=self.attr)
assert attr_val.value_as_text == "Yes"

def test_boolean_value_as_text_false(self):
product = factories.ProductFactory()
self.attr.save_value(product, False)
attr_val = product.attribute_values.get(attribute=self.attr)
assert attr_val.value_as_text == "No"



class TestMultiOptionAttributes(TestCase):

Expand Down

0 comments on commit 3dee0ae

Please sign in to comment.