Wed Dec 14 20:05:19 EET 2005 [EMAIL PROTECTED]
* Fix the checkbox-and-hidden support.
The patch "Add submit buttons to multiple identical control checks" by
[EMAIL PROTECTED] broke the feature allowing checkbox and hidden form
fields with the same name, introduced in patch "Allow multiple
checkbox form fields with same name." Split out the changes introduced
by palfrey to separate function, add unit test for the checkbox case.
New patches:
[Fix the checkbox-and-hidden support.
[EMAIL PROTECTED]
The patch "Add submit buttons to multiple identical control checks" by
[EMAIL PROTECTED] broke the feature allowing checkbox and hidden form
fields with the same name, introduced in patch "Allow multiple
checkbox form fields with same name." Split out the changes introduced
by palfrey to separate function, add unit test for the checkbox case.
]
<
> {
hunk ./tests/test-form.twill 71
fv 1 item test
submit
find "==item AND selecttest=="
+
+###
+
+go /test_checkbox
+code 200
+submit
+code 200
+find "CHECKBOXTEST: ==False=="
+
+fv 1 checkboxtest True
+submit
+code 200
+find "CHECKBOXTEST: ==True=="
hunk ./tests/twilltestserver.py 91
'login', ('test spaces', 'test_spaces'), 'test_spaces',
'simpleform', 'upload_file', 'http_auth', 'formpostredirect',
'exit', 'multisubmitform', "exception", "plaintext",
- "testform", "testformaction", "test_refresh"]
+ "testform", "testformaction", "test_refresh",
+ "test_checkbox"]
def __init__(self):
self.restricted = Restricted()
hunk ./tests/twilltestserver.py 242
<input type=text name=item_b>
<input type=text name=item_c>
+<input type=submit value=post>
+</form>
+""" % (s,)
+
+ def test_checkbox(self):
+ request = get_request()
+
+ s = ""
+ if request.form and request.form.has_key('checkboxtest'):
+ val = request.form['checkboxtest']
+
+ if not isinstance(val, str):
+ val = val[0]
+
+ s += "CHECKBOXTEST: ==%s==<p>" % val
+
+ return """\
+%s
+<form method=POST>
+
+<input type="checkbox" name="checkboxtest" value="True">
+<input type="hidden" name="checkboxtest" value="False">
+
<input type=submit value=post>
</form>
""" % (s,)
hunk ./twill/browser.py 331
return None
- def _all_the_same_control(self, matches):
+ def _all_the_same_checkbox(self, matches):
+ """
+ Check whether all these controls are actually the the same
+ checkbox.
+
+ Hidden controls can combine with checkboxes, to allow form
+ processors to ensure a False value is returned even if user
+ does not check the checkbox. Without the hidden control, no
+ value would be returned.
+ """
+ name = None
+ for match in matches:
+ if match.type not in ['checkbox', 'hidden']:
+ return False
+ if name is None:
+ name = match.name
+ else:
+ if match.name != name:
+ return False
+ return True
+
+ def _all_the_same_submit(self, matches):
name = None
value = None
for match in matches:
hunk ./twill/browser.py 356
- if match.type not in ['checkbox', 'hidden', 'submit']:
+ if match.type not in ['submit', 'hidden']:
return False
if name is None:
name = match.name
hunk ./twill/browser.py 379
# test exact match.
if matches:
if (len(matches) == 1
- or self._all_the_same_control(matches)):
+ or (self._all_the_same_checkbox(matches)
+ or self._all_the_same_submit(matches))):
found = matches[0]
else:
found_multiple = True # record for error reporting.
hunk ./twill/browser.py 406
if matches:
if (len(matches) == 1
- or self._all_the_same_control(matches)):
+ or (self._all_the_same_checkbox(matches)
+ or self._all_the_same_submit(matches))):
found = matches[0]
else:
found_multiple = True # record for error
}
Context:
[TAG release-0.8.1
[EMAIL PROTECTED]
Patch bundle hash:
742e7eb21b8da9f379f0ab64a7994392fd0cd6fe
_______________________________________________
twill mailing list
[email protected]
http://lists.idyll.org/listinfo/twill