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,11 +18,14 @@ 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'
def placeholder():
df = date_format or get_format('DATE_INPUT_FORMATS')[0] df = date_format or get_format('DATE_INPUT_FORMATS')[0]
date_attrs['placeholder'] = now().replace( return now().replace(
year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0 year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0
).strftime(df) ).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,11 +39,14 @@ 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'
def placeholder():
tf = time_format or get_format('TIME_INPUT_FORMATS')[0] tf = time_format or get_format('TIME_INPUT_FORMATS')[0]
time_attrs['placeholder'] = now().replace( return now().replace(
year=2000, month=12, day=31, hour=18, minute=0, second=0, microsecond=0 year=2000, month=1, day=1, hour=0, minute=0, second=0, microsecond=0
).strftime(tf) ).strftime(tf)
time_attrs['placeholder'] = lazy(placeholder, str)
forms.TimeInput.__init__(self, time_attrs, time_format) forms.TimeInput.__init__(self, time_attrs, time_format)