wip: CheckboxesWidget corrections
This commit is contained in:
parent
93d25abdda
commit
c29fd73345
|
@ -452,18 +452,53 @@ def test_select_or_other_widget():
|
|||
assert widget.parse() == 'Apricot'
|
||||
|
||||
|
||||
def test_checkboxes_widget():
|
||||
def test_checkboxes_with_name():
|
||||
widget = CheckboxesWidget('test',
|
||||
options=[('apple', 'Apple', 'apple'), ('pear', 'Pear', 'pear'), ('peach', 'Peach', 'peach')])
|
||||
mock_form_submission(req, widget, {'test$elementpeach': ['yes'], 'test$elementpear': ['yes']})
|
||||
assert widget.parse() == ['pear', 'peach']
|
||||
|
||||
def test_checkboxes_widget_without_name():
|
||||
def test_checkboxes_without_name():
|
||||
widget = CheckboxesWidget('test', options=[('apple', 'Apple')])
|
||||
mock_form_submission(req, widget, {'test$element0': ['yes']})
|
||||
with pytest.raises(mechanize.ControlNotFoundError):
|
||||
mock_form_submission(req, widget, {'test$element1': ['yes']})
|
||||
assert widget.parse() == ['apple']
|
||||
|
||||
def test_checkboxes_widget_submission_with_options():
|
||||
def test_checkboxes_with_disabled_options():
|
||||
widget = CheckboxesWidget('test',
|
||||
options_with_attributes=[
|
||||
('apple', 'Apple', 'apple', {}),
|
||||
('pear', 'Pear', 'pear', {'disabled': True}),
|
||||
('peach', 'Peach', 'peach', {})])
|
||||
mock_form_submission(req, widget, {'test$elementapple': ['yes']})
|
||||
assert widget.parse() == ['apple']
|
||||
widget2 = CheckboxesWidget('test2',
|
||||
options_with_attributes=[
|
||||
('apple', 'Apple', 'apple', {'disabled': True}),
|
||||
('pear', 'Pear', 'pear', {'disabled': True}),
|
||||
('peach', 'Peach', 'peach',{'disabled': True})])
|
||||
# with pytest.raises(AttributeError):
|
||||
# mechanize will
|
||||
# raise AttributeError(
|
||||
# "insufficient non-disabled items with name %s" % name)
|
||||
# as the item is disabled
|
||||
#mock_form_submission(req, widget2, {'test2$elementpear': ['yes']})
|
||||
assert len(widget2.disabled_options) == 3
|
||||
assert widget2.parse() == []
|
||||
for widget in widget2.get_widgets():
|
||||
assert widget.attrs['disabled'] is True
|
||||
|
||||
def test_checkboxes_with_attributes():
|
||||
test_dt = datetime.datetime.now()
|
||||
widget = CheckboxesWidget('test', inline=False, readonly=True, max_choices=3,
|
||||
options=[('apple', 'Apple', 'apple')])
|
||||
assert widget.inline is False
|
||||
assert widget.readonly is True
|
||||
assert widget.max_choices == 3
|
||||
assert widget.extra_attributes == [None]
|
||||
|
||||
def test_checkboxes_submission_with_options():
|
||||
test_dt = datetime.datetime.now()
|
||||
widget = CheckboxesWidget('test',
|
||||
options_with_attributes=[
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
{% extends "qommon/forms/widget.html" %}
|
||||
{% block widget-control %}
|
||||
<ul {% if widget.inline %}class="inline"{% endif %}>
|
||||
<ul id="form_{{ widget.name }}" {% if widget.inline %}class="inline"{% endif %}>
|
||||
{% for option in widget.get_options %}
|
||||
<li {% if option.disabled %}class="disabled"{% endif %}>
|
||||
<label>
|
||||
{% if widget.readonly %}<input type="hidden" name="{{option.name}}" value="{{option.value}}" >{% endif %}
|
||||
<input type="checkbox" value="{{option.value}}" name="{{option.name}}{% if option.disabled %}xx{% endif %}"{% if option.disabled %} disabled{% endif %}{% if option.checked %} checked="checked"{% endif %} id="form_{{option.name}}">
|
||||
{% if widget.readonly %}<input type="hidden" name="{{ option.name }}" value="{{ option.value }}" >{% endif %}
|
||||
<input type="checkbox" value="{{ option.value }}"{% if widget.readonly %} name="{{ option.name }}"{% endif %}{% if option.disabled %} disabled{% endif %}{% if option.checked %} checked="checked"{% endif %}>
|
||||
<span>{{ option.title }}</span></label>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in New Issue