Projet

Général

Profil

0001-backoffice-don-t-consider-filters-as-templates-if-th.patch

Frédéric Péters, 23 septembre 2022 10:29

Télécharger (4 ko)

Voir les différences:

Subject: [PATCH] backoffice: don't consider filters as templates if there are
 brackets (#69458)

 tests/backoffice_pages/test_filters.py | 15 ++++++++++++++-
 wcs/backoffice/management.py           |  4 ++--
 wcs/qommon/template.py                 |  6 ++++--
 3 files changed, 20 insertions(+), 5 deletions(-)
tests/backoffice_pages/test_filters.py
760 760
    formdef.fields = [
761 761
        fields.StringField(
762 762
            id='4', label='4th field', type='string', display_locations=['validation', 'summary', 'listings']
763
        )
763
        ),
764
        fields.StringField(
765
            id='5', label='5th field', type='string', display_locations=['validation', 'summary', 'listings']
766
        ),
764 767
    ]
765 768
    formdef.workflow_roles = {'_receiver': role.id}
766 769
    formdef.store()
......
772 775
        formdata = data_class()
773 776
        formdata.data = {}
774 777
        formdata.data['4'] = 'a' if bool(i % 2) else 'b'
778
        formdata.data['5'] = '[a]' if bool(i % 2) else '[b]'
775 779
        formdata.just_created()
776 780
        formdata.jump_status('new')
777 781
        formdata.store()
......
808 812
    assert resp.text.count('<td>a</td>') > 0
809 813
    assert resp.text.count('<td>b</td>') == 0
810 814

  
815
    # filter on something looking like an ezt template
816
    resp.forms['listing-settings']['filter-4'].checked = False
817
    resp.forms['listing-settings']['filter-5'].checked = True
818
    resp = resp.forms['listing-settings'].submit()
819
    resp.forms['listing-settings']['filter-5-value'].value = '[b]'
820
    resp = resp.forms['listing-settings'].submit()
821
    assert resp.text.count('<td>[a]</td>') == 0
822
    assert resp.text.count('<td>[b]</td>') > 0
823

  
811 824

  
812 825
def test_backoffice_string_filter_int_value(pub):
813 826
    pub.user_class.wipe()
wcs/backoffice/management.py
1916 1916
                            % (value, operator)
1917 1917
                        )
1918 1918

  
1919
                if Template.is_template_string(filter_field_value):
1919
                if Template.is_template_string(filter_field_value, ezt_support=False):
1920 1920
                    if keep_templates:
1921 1921
                        criterias.append(criteria('id', filter_field_value))
1922 1922
                        continue
......
1968 1968
                else:
1969 1969
                    raise RequestError('Invalid value "%s" for "%s"' % (filter_field_value, filter_field_key))
1970 1970
            elif filter_field.type in ('item', 'items', 'string', 'email'):
1971
                if Template.is_template_string(filter_field_value):
1971
                if Template.is_template_string(filter_field_value, ezt_support=False):
1972 1972
                    if keep_templates:
1973 1973
                        criterias.append(criteria(filter_field.id, filter_field_value))
1974 1974
                        continue
wcs/qommon/template.py
539 539
        return force_str(fd.getvalue())
540 540

  
541 541
    @classmethod
542
    def is_template_string(cls, string):
543
        return isinstance(string, str) and ('{{' in string or '{%' in string or '[' in string)
542
    def is_template_string(cls, string, ezt_support=True):
543
        return isinstance(string, str) and (
544
            '{{' in string or '{%' in string or ('[' in string and ezt_support)
545
        )
544 546

  
545 547

  
546 548
# monkey patch django template Variable resolution to convert legacy
547
-