backoffice: ignore filter dates with leading 0 (#56205)

This commit is contained in:
Frédéric Péters 2021-08-23 10:14:46 +02:00
parent db05d872e9
commit 70fc9d0c21
3 changed files with 14 additions and 0 deletions

View File

@ -865,6 +865,11 @@ def test_backoffice_filter(pub):
resp = resp.forms['listing-settings'].submit()
assert resp.text.count('<td>baz</td>') == 8
# and dates being typed in are properly ignored
resp.forms['listing-settings']['filter-start-value'] = '0020-02-01'
resp = resp.forms['listing-settings'].submit()
assert resp.text.count('<td>baz</td>') == 8
# check it's also ok for end filter
resp.forms['listing-settings']['filter-end'].checked = True
resp = resp.forms['listing-settings'].submit()

View File

@ -251,6 +251,10 @@ def date_format():
def get_as_datetime(s):
if s and re.match(r'^0\d\d\d-\d\d-\d\d$', s):
# iso date with year starting with 0, it's likely currently being
# typed in an HTML5 date input widget, consider it invalid.
raise ValueError('invalid date, leading 0')
formats = [datetime_format(), date_format()] # prefer current locale
for value in DATETIME_FORMATS.values():
formats.extend(value)

View File

@ -347,6 +347,11 @@ $(function() {
/* automatically refresh onfilter change */
$('form#listing-settings input[type=date], form#listing-settings input[type=text], form#listing-settings select').change(function() {
if (this.type == 'date' && $(this).val() && $(this).val()[0] == '0') {
// input date with year starting with 0, it's currently being typed in,
// wait for the year to be complete before acting on it.
return;
}
if ($(this).is('select[data-allow-template]') && $(this).val() == '{}') {
var replacement_input = $('<input></input>', {type: 'text', name: $(this).attr('name')});
$(this).parent().removeClass('SingleSelectWidget').addClass('StringWidget');