Просмотр исходного кода

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

* 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>
master
wlaw01 2 лет назад
Родитель
Сommit
3dee0ae8fb
Аккаунт пользователя с таким Email не найден

+ 6
- 0
src/oscar/apps/catalogue/abstract_models.py Просмотреть файл

@@ -1142,6 +1142,12 @@ class AbstractProductAttributeValue(models.Model):
1142 1142
         """
1143 1143
         return str(self.value)
1144 1144
 
1145
+    @property
1146
+    def _boolean_as_text(self):
1147
+        if self.value:
1148
+            return _("Yes")
1149
+        return _("No")
1150
+
1145 1151
     @property
1146 1152
     def value_as_html(self):
1147 1153
         """

+ 13
- 0
tests/integration/catalogue/test_attributes.py Просмотреть файл

@@ -68,6 +68,19 @@ class TestBooleanAttributes(TestCase):
68 68
         with self.assertRaises(ValidationError):
69 69
             self.attr.validate_value(1)
70 70
 
71
+    def test_boolean_value_as_text_true(self):
72
+        product = factories.ProductFactory()
73
+        self.attr.save_value(product, True)
74
+        attr_val = product.attribute_values.get(attribute=self.attr)
75
+        assert attr_val.value_as_text == "Yes"
76
+
77
+    def test_boolean_value_as_text_false(self):
78
+        product = factories.ProductFactory()
79
+        self.attr.save_value(product, False)
80
+        attr_val = product.attribute_values.get(attribute=self.attr)
81
+        assert attr_val.value_as_text == "No"
82
+
83
+
71 84
 
72 85
 class TestMultiOptionAttributes(TestCase):
73 86
 

Загрузка…
Отмена
Сохранить