diff --git a/src/wuttaweb/forms/schema.py b/src/wuttaweb/forms/schema.py index 5e0364e..6deb56d 100644 --- a/src/wuttaweb/forms/schema.py +++ b/src/wuttaweb/forms/schema.py @@ -280,13 +280,59 @@ class WuttaQuantity(colander.Decimal): return self.app.render_quantity(appstruct) -class WuttaSet(colander.Set): +class WuttaList(colander.List): """ - Custom schema type for :class:`python:set` fields. - - This is a subclass of :class:`colander.Set`. + Custom schema type for :class:`python:list` fields; this is a + subclass of :class:`colander.List`. :param request: Current :term:`request` object. + + As of now this merely provides a way (in fact, requires you) to + pass the request in, so it can be leveraged as needed. Instances + of this type will have the following attributes: + + .. attribute:: request + + Reference to the current :term:`request`. + + .. attribute:: config + + Reference to the app :term:`config object`. + + .. attribute:: app + + Reference to the :term:`app handler` instance. + """ + + def __init__(self, request): + super().__init__() + self.request = request + self.config = self.request.wutta_config + self.app = self.config.get_app() + + +class WuttaSet(colander.Set): + """ + Custom schema type for :class:`python:set` fields; this is a + subclass of :class:`colander.Set`. + + :param request: Current :term:`request` object. + + As of now this merely provides a way (in fact, requires you) to + pass the request in, so it can be leveraged as needed. Instances + of this type will have the following attributes: + + .. attribute:: request + + Reference to the current :term:`request`. + + .. attribute:: config + + Reference to the app :term:`config object`. + + .. attribute:: app + + Reference to the :term:`app handler` instance. """ def __init__(self, request): diff --git a/tests/forms/test_schema.py b/tests/forms/test_schema.py index 844cb44..d6b7420 100644 --- a/tests/forms/test_schema.py +++ b/tests/forms/test_schema.py @@ -198,6 +198,26 @@ class TestWuttaMoney(WebTestCase): self.assertEqual(widget.scale, 4) +class TestWuttaList(WebTestCase): + + def test_constructor(self): + node = colander.SchemaNode(mod.WuttaList(self.request)) + typ = node.typ + self.assertIs(typ.request, self.request) + self.assertIs(typ.config, self.config) + self.assertIs(typ.app, self.app) + + +class TestWuttaSet(WebTestCase): + + def test_constructor(self): + node = colander.SchemaNode(mod.WuttaSet(self.request)) + typ = node.typ + self.assertIs(typ.request, self.request) + self.assertIs(typ.config, self.config) + self.assertIs(typ.app, self.app) + + class TestWuttaQuantity(WebTestCase): def test_serialize(self):