3
0
Fork 0

fix: make WuttaQuantity serialize w/ app handler, remove custom widget

turns out we need to always serialize the value via render_quantity()
and the widget becomes redundant
This commit is contained in:
Lance Edgar 2025-01-07 13:34:42 -06:00
parent b5b88e2a7b
commit b73127e350
5 changed files with 31 additions and 76 deletions

View file

@ -143,36 +143,6 @@ class TestWuttaMoneyInputWidget(WebTestCase):
self.assertEqual(result, '<span></span>')
class TestWuttaQuantityWidget(WebTestCase):
def make_field(self, node, **kwargs):
# TODO: not sure why default renderer is in use even though
# pyramid_deform was included in setup? but this works..
kwargs.setdefault('renderer', deform.Form.default_renderer)
return deform.Field(node, **kwargs)
def make_widget(self, **kwargs):
return mod.WuttaQuantityWidget(self.request, **kwargs)
def test_serialize(self):
node = colander.SchemaNode(schema.WuttaQuantity(self.request))
field = self.make_field(node)
widget = self.make_widget()
amount = decimal.Decimal('42.00')
# editable widget has normal text input
result = widget.serialize(field, str(amount))
self.assertIn('<b-input', result)
# readonly is rendered per app convention
result = widget.serialize(field, str(amount), readonly=True)
self.assertEqual(result, '<span>42</span>')
# readonly w/ null value
result = widget.serialize(field, None, readonly=True)
self.assertEqual(result, '<span></span>')
class TestFileDownloadWidget(WebTestCase):
def make_field(self, node, **kwargs):