Projet

Général

Profil

0001-fields-allow-none-prefill-in-items-fields-67843.patch

Thomas Noël, 01 août 2022 12:28

Télécharger (2,51 ko)

Voir les différences:

Subject: [PATCH] fields: allow none prefill in items fields (#67843)

 tests/form_pages/test_all.py | 23 +++++++++++++++++++++++
 wcs/fields.py                |  4 +++-
 2 files changed, 26 insertions(+), 1 deletion(-)
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
            {'type': 'none'},
3759
            {'type': 'string', 'value': '{{ None }}'},
3760
            {'type': 'formula', 'value': 'None'},
3761
        ]:
3762
            formdef.fields[0] = fields.ItemsField(
3763
                id='0',
3764
                varname='items',
3765
                label='items',
3766
                data_source=ds,
3767
                display_disabled_items=True,
3768
                prefill=none_prefill_value,
3769
            )
3770
            formdef.store()
3771

  
3772
            # it will use foo,bar as selected in the first part of this test
3773
            resp = get_app(pub).get('/test/')
3774
            assert not resp.form['f0$elementfoo'].checked
3775
            assert not resp.form['f0$elementbar'].checked
3776
            assert not resp.form['f0$elementbaz'].checked
3777
            assert pub.loggederror_class.count() == 0
3778

  
3756 3779

  
3757 3780
def test_form_page_changing_prefill(pub):
3758 3781
    formdef = create_formdef()
wcs/fields.py
2562 2562

  
2563 2563
    def get_prefill_value(self, user=None, force_string=True):
2564 2564
        value, explicit_lock = super().get_prefill_value(user=user, force_string=False)
2565
        if not isinstance(value, (str, tuple, list)) or not all(isinstance(x, (int, str)) for x in value):
2565
        if value is not None and (
2566
            not isinstance(value, (str, tuple, list)) or not all(isinstance(x, (int, str)) for x in value)
2567
        ):
2566 2568
            get_publisher().record_error(
2567 2569
                _('Invalid value for items prefill on field "%s"') % self.label,
2568 2570
                formdef=getattr(self, 'formdef', None),
2569
-