0001-created-Checkboxeswidget.get_options-and-tests-23413.patch
tests/test_widgets.py | ||
---|---|---|
2 | 2 |
import sys |
3 | 3 |
import shutil |
4 | 4 |
import copy |
5 |
import collections |
|
5 | 6 | |
6 | 7 |
from quixote import cleanup |
7 | 8 |
from quixote.http_request import parse_query |
... | ... | |
407 | 408 | |
408 | 409 |
def test_checkboxes_widget(): |
409 | 410 |
widget = CheckboxesWidget('test', |
410 |
options=[('apple', 'Apple', 'apple'), ('pear', 'Pear', 'pear'), ('peach', 'Peach', 'peach')]) |
|
411 |
options=[('apple', 'Apple', 'apple', {'datetime': datetime.datetime.now()}), ('pear', 'Pear', 'pear'), ('peach', 'Peach', 'peach')])
|
|
411 | 412 |
mock_form_submission(req, widget, {'test$elementpeach': ['yes'], 'test$elementpear': ['yes']}) |
412 | 413 |
assert widget.parse() == ['pear', 'peach'] |
413 | 414 | |
415 |
def test_checkboxes_widget_options(): |
|
416 |
test_dt = datetime.datetime.now() |
|
417 |
widget = CheckboxesWidget('test', |
|
418 |
options_with_attributes=[('apple', 'Apple', 'apple', {'datetime': test_dt}), ('pear', 'Pear', 'pear', {'datetime': test_dt}), ('peach', 'Peach', 'peach', {'datetime': test_dt})]) |
|
419 |
assert isinstance(widget.get_options(), collections.Iterator) |
|
420 |
iter_options = list(widget.get_options()) |
|
421 |
assert len(iter_options) > 0 |
|
422 |
for option in iter_options: |
|
423 |
attributes = option['attrs'] |
|
424 |
assert attributes.get('value', False) |
|
425 |
assert attributes.get('name', False) |
|
426 |
assert option.get('description', False) |
|
427 |
assert option.get('attrs', False) |
|
428 |
assert option.get('options', False) |
|
429 |
assert option['options']['datetime'] == test_dt |
|
430 | ||
414 | 431 | |
415 | 432 |
def test_composite_widget(): |
416 | 433 |
widget = CompositeWidget('compotest') |
wcs/qommon/form.py | ||
---|---|---|
1109 | 1109 |
def has_error(self, request=None): |
1110 | 1110 |
return Widget.has_error(self, request=request) |
1111 | 1111 | |
1112 |
def get_options(self): |
|
1113 |
options = [] |
|
1114 |
tags = [] |
|
1115 | ||
1116 |
if self.options_with_attributes: |
|
1117 |
options = self.options_with_attributes[:] |
|
1118 | ||
1119 |
for option in options: |
|
1120 |
name, description, key = option[:3] |
|
1121 |
html_attrs = {} |
|
1122 |
html_attrs['value'] = key |
|
1123 |
html_attrs['name'] = name |
|
1124 |
if self.options_with_attributes and option[-1].get('disabled'): |
|
1125 |
html_attrs['disabled'] = 'disabled' |
|
1126 |
if self.options_with_attributes and option[-1].get('checked'): |
|
1127 |
html_attrs['checked'] = 'checked' |
|
1128 |
if description is None: |
|
1129 |
description = '' |
|
1130 | ||
1131 |
yield { |
|
1132 |
'description': description, |
|
1133 |
'attrs': html_attrs, |
|
1134 |
'options': option[-1] if self.options_with_attributes else None |
|
1135 |
} |
|
1136 | ||
1112 | 1137 |
def render_content(self): |
1113 | 1138 |
r = TemplateIO(html=True) |
1114 | 1139 |
if self.inline: |
1115 |
- |