summaryrefslogtreecommitdiff
path: root/bootstrap_datepicker
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-01-15 18:34:54 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-01-15 18:34:54 +0100
commit8b9880fb22e0f58d1cbde5720e173ad164cb5a1f (patch)
tree0b0e03536d5e20e14a13d7805ce1e75f1fca04ea /bootstrap_datepicker
parent1f374dd36b2901b35e4ab0bdbcfcbcbb93224f1a (diff)
downloadIshtar-8b9880fb22e0f58d1cbde5720e173ad164cb5a1f.tar.bz2
Ishtar-8b9880fb22e0f58d1cbde5720e173ad164cb5a1f.zip
UI: adapt each form to use the new date widget. Force localization of format.
Diffstat (limited to 'bootstrap_datepicker')
-rw-r--r--bootstrap_datepicker/widgets.py31
1 files changed, 16 insertions, 15 deletions
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);
</script>'''
- 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))