Lazy-format placeholders in DateField and TimeField

This commit is contained in:
Raphael Michel
2021-01-20 15:45:13 +01:00
parent fdc555f74f
commit f3de5d5c96

View File

@@ -18,10 +18,13 @@ class DatePickerWidget(forms.DateInput):
date_attrs['class'] += ' datepickerfield' date_attrs['class'] += ' datepickerfield'
date_attrs['autocomplete'] = 'date-picker-do-not-autofill' date_attrs['autocomplete'] = 'date-picker-do-not-autofill'
df = date_format or get_format('DATE_INPUT_FORMATS')[0] def placeholder():
date_attrs['placeholder'] = now().replace( df = date_format or get_format('DATE_INPUT_FORMATS')[0]
year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0 return now().replace(
).strftime(df) year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0
).strftime(df)
date_attrs['placeholder'] = lazy(placeholder, str)
forms.DateInput.__init__(self, date_attrs, date_format) forms.DateInput.__init__(self, date_attrs, date_format)
@@ -36,10 +39,13 @@ class TimePickerWidget(forms.TimeInput):
time_attrs['class'] += ' timepickerfield' time_attrs['class'] += ' timepickerfield'
time_attrs['autocomplete'] = 'time-picker-do-not-autofill' time_attrs['autocomplete'] = 'time-picker-do-not-autofill'
tf = time_format or get_format('TIME_INPUT_FORMATS')[0] def placeholder():
time_attrs['placeholder'] = now().replace( tf = time_format or get_format('TIME_INPUT_FORMATS')[0]
year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0 return now().replace(
).strftime(tf) year=2000, month=1, day=1, hour=0, minute=0, second=0, microsecond=0
).strftime(tf)
time_attrs['placeholder'] = lazy(placeholder, str)
forms.TimeInput.__init__(self, time_attrs, time_format) forms.TimeInput.__init__(self, time_attrs, time_format)