Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show boolean option value to yes/no in stead of true/false #4005

Merged
merged 3 commits into from Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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