From cd8cf5bc21229d3c201687fcfb5bece068e8f34c 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 | 16 ++++++++++ wcs/qommon/form.py | 30 +++++-------------- .../qommon/forms/widgets/checkboxes.html | 18 +++++++++++ 3 files changed, 42 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..50c97f20 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,21 @@ def test_checkboxes_widget(): mock_form_submission(req, widget, {'test$elementpeach': ['yes'], 'test$elementpear': ['yes']}) assert widget.parse() == ['pear', 'peach'] +def test_checkboxes_widget_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})]) + assert isinstance(widget.get_options(), collections.Iterator) + iter_options = list(widget.get_options()) + 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..3b0b6406 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -1109,28 +1109,14 @@ 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('