0002-fields-allow-none-prefill-in-items-fields-67843.patch
tests/form_pages/test_all.py | ||
---|---|---|
3753 | 3753 |
assert logged_error.summary == 'Invalid value for items prefill on field "items"' |
3754 | 3754 |
pub.loggederror_class.wipe() |
3755 | 3755 | |
3756 |
# check with a "none" explicit prefill, or a None value |
|
3757 |
for none_prefill_value in [ |
|
3758 |
{}, |
|
3759 |
{'type': 'none'}, |
|
3760 |
{'type': 'string', 'value': '{{ None }}'}, |
|
3761 |
{'type': 'formula', 'value': 'None'}, |
|
3762 |
]: |
|
3763 |
formdef.fields[0] = fields.ItemsField( |
|
3764 |
id='0', |
|
3765 |
varname='items', |
|
3766 |
label='items', |
|
3767 |
data_source=ds, |
|
3768 |
display_disabled_items=True, |
|
3769 |
prefill=none_prefill_value, |
|
3770 |
) |
|
3771 |
formdef.store() |
|
3772 | ||
3773 |
# all checkboxes will be left unchecked |
|
3774 |
resp = get_app(pub).get('/test/') |
|
3775 |
assert not resp.form['f0$elementfoo'].checked |
|
3776 |
assert not resp.form['f0$elementbar'].checked |
|
3777 |
assert not resp.form['f0$elementbaz'].checked |
|
3778 |
assert pub.loggederror_class.count() == 0 |
|
3779 | ||
3756 | 3780 | |
3757 | 3781 |
def test_form_page_changing_prefill(pub): |
3758 | 3782 |
formdef = create_formdef() |
wcs/fields.py | ||
---|---|---|
2570 | 2570 | |
2571 | 2571 |
def get_prefill_value(self, user=None, force_string=True): |
2572 | 2572 |
value, explicit_lock = super().get_prefill_value(user=user, force_string=False) |
2573 |
if not isinstance(value, (str, tuple, list)) or not all(isinstance(x, (int, str)) for x in value): |
|
2573 |
if value is not None and ( |
|
2574 |
not isinstance(value, (str, tuple, list)) or not all(isinstance(x, (int, str)) for x in value) |
|
2575 |
): |
|
2574 | 2576 |
get_publisher().record_error( |
2575 | 2577 |
_('Invalid value for items prefill on field "%s"') % self.label, |
2576 | 2578 |
formdef=getattr(self, 'formdef', None), |
2577 |
- |