From a33ee7dac0ee1f1c561664598eddfdfa3d2e9314 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 15 Jan 2018 18:34:54 +0100 Subject: UI: adapt each form to use the new date widget. Force localization of format. --- bootstrap_datepicker/widgets.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'bootstrap_datepicker') diff --git a/bootstrap_datepicker/widgets.py b/bootstrap_datepicker/widgets.py index e21d11939..85a651efc 100644 --- a/bootstrap_datepicker/widgets.py +++ b/bootstrap_datepicker/widgets.py @@ -86,7 +86,8 @@ class DatePicker(DateTimeInput): })(window); ''' - def __init__(self, attrs=None, format=None, options=None, div_attrs=None, icon_attrs=None): + def __init__(self, attrs=None, format=None, options=None, div_attrs=None, + icon_attrs=None): if not icon_attrs: icon_attrs = {'class': 'fa fa-calendar fa-2'} if not div_attrs: @@ -99,12 +100,10 @@ class DatePicker(DateTimeInput): self.div_attrs = div_attrs and div_attrs.copy() or {} self.icon_attrs = icon_attrs and icon_attrs.copy() or {} self.picker_id = self.div_attrs.get('id') or None - if options is False: # datepicker will not be initalized when options is False - self.options = False - else: - self.options = options and options.copy() or {} - if format and not self.options.get('format') and not self.attrs.get('date-format'): - self.options['format'] = self.conv_datetime_format_py2js(format) + self.options = options and options.copy() or {} + if format and not self.options.get('format') and not self.attrs.get( + 'date-format'): + self.options['format'] = self.conv_datetime_format_py2js(format) def render(self, name, value, attrs=None): if value is None: @@ -116,18 +115,20 @@ class DatePicker(DateTimeInput): if value != '': # Only add the 'value' attribute if a value is non-empty. input_attrs['value'] = force_text(self._format_value(value)) - input_attrs = {key: conditional_escape(val) for key, val in input_attrs.items()} + input_attrs = {key: conditional_escape(val) + for key, val in input_attrs.items()} if not self.picker_id: - self.picker_id = (input_attrs.get('id', '') + '_pickers').replace(' ', '_') + self.picker_id = (input_attrs.get('id', '') + '_pickers' + ).replace(' ', '_') self.div_attrs['id'] = self.picker_id picker_id = conditional_escape(self.picker_id) - div_attrs = {key: conditional_escape(val) for key, val in self.div_attrs.items()} - icon_attrs = {key: conditional_escape(val) for key, val in self.icon_attrs.items()} + div_attrs = {key: conditional_escape(val) + for key, val in self.div_attrs.items()} + icon_attrs = {key: conditional_escape(val) + for key, val in self.icon_attrs.items()} html = self.html_template % dict(div_attrs=flatatt(div_attrs), input_attrs=flatatt(input_attrs), icon_attrs=flatatt(icon_attrs)) - if self.options: - js = self.js_template % dict(picker_id=picker_id, options=json_dumps(self.options or {})) - else: - js = '' + js = self.js_template % dict(picker_id=picker_id, + options=json_dumps(self.options or {})) return mark_safe(force_text(html + js)) -- cgit v1.2.3