From 666ed6e0f499e238a32ea68b0c38073c4a76ab3e Mon Sep 17 00:00:00 2001 From: Elias Showk Date: Thu, 3 May 2018 10:50:13 +0200 Subject: [PATCH] add CheckboxesWidget.get_options and checkboxes.html (#23413) --- tests/test_widgets.py | 26 +++++++++++++++++ wcs/qommon/form.py | 29 +++++-------------- .../qommon/forms/widgets/checkboxes.html | 18 ++++++++++++ 3 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 wcs/qommon/templates/qommon/forms/widgets/checkboxes.html diff --git a/tests/test_widgets.py b/tests/test_widgets.py index b58e6a32..68b487c0 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -2,6 +2,7 @@ import datetime import sys import shutil import copy +import collections from quixote import cleanup from quixote.http_request import parse_query @@ -411,6 +412,31 @@ def test_checkboxes_widget(): mock_form_submission(req, widget, {'test$elementpeach': ['yes'], 'test$elementpear': ['yes']}) assert widget.parse() == ['pear', 'peach'] +def test_checkboxes_widget_submission_with_options(): + test_dt = datetime.datetime.now() + widget = CheckboxesWidget('test', + options_with_attributes=[ + ('apple', 'Apple', 'apple', {'datetime': test_dt}), + ('pear', 'Pear', 'pear', {'datetime': test_dt}), + ('peach', 'Peach', 'peach', {'datetime': test_dt})]) + mock_form_submission(req, widget, {'test$elementpeach': ['yes'], 'test$elementpear': ['yes']}) + assert widget.parse() == ['pear', 'peach'] + +def test_checkboxes_get_widgets(): + test_dt = datetime.datetime.now() + widget = CheckboxesWidget('test', + options_with_attributes=[ + ('apple', 'Apple', 'apple', {'datetime': test_dt}), + ('pear', 'Pear', 'pear', {'datetime': test_dt}), + ('peach', 'Peach', 'peach', {'datetime': test_dt})]) + assert isinstance(widget.get_widgets(), collections.Iterator) + iter_options = list(widget.get_widgets()) + assert len(iter_options) == 3 + for widget in iter_options: + assert isinstance(widget, CheckboxWidget) + assert isinstance(widget.extra_options, dict) + assert widget.extra_options['datetime'] == test_dt + def test_composite_widget(): widget = CompositeWidget('compotest') diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py index 49df467e..947914d0 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -1109,28 +1109,13 @@ class CheckboxesWidget(CompositeWidget): def has_error(self, request=None): return Widget.has_error(self, request=request) - def render_content(self): - r = TemplateIO(html=True) - if self.inline: - r += htmltext('