Parcourir la source

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 il y a 2 ans
Parent
révision
3dee0ae8fb
Aucun compte lié à l'adresse e-mail de l'auteur

+ 6
- 0
src/oscar/apps/catalogue/abstract_models.py Voir le fichier

1142
         """
1142
         """
1143
         return str(self.value)
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
     @property
1151
     @property
1146
     def value_as_html(self):
1152
     def value_as_html(self):
1147
         """
1153
         """

+ 13
- 0
tests/integration/catalogue/test_attributes.py Voir le fichier

68
         with self.assertRaises(ValidationError):
68
         with self.assertRaises(ValidationError):
69
             self.attr.validate_value(1)
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
 class TestMultiOptionAttributes(TestCase):
85
 class TestMultiOptionAttributes(TestCase):
73
 
86
 

Chargement…
Annuler
Enregistrer