diff --git a/bootstrap3_datetime/widgets.py b/bootstrap3_datetime/widgets.py index 126dd59..7fd8cd9 100644 --- a/bootstrap3_datetime/widgets.py +++ b/bootstrap3_datetime/widgets.py @@ -5,7 +5,7 @@ from django.forms.widgets import DateTimeInput from django.utils.safestring import mark_safe from django.utils.html import conditional_escape -from django.utils.encoding import force_text +from django.utils.encoding import force_str class DateTimePicker(DateTimeInput): @@ -101,7 +101,7 @@ def render(self, name, value, attrs=None, renderer=None): if value != '': # Only add the 'value' attribute if a value is non-empty. - input_attrs['value'] = force_text(self._format_value(value)) + input_attrs['value'] = force_str(self._format_value(value)) 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', '') + @@ -117,4 +117,4 @@ def render(self, name, value, attrs=None, renderer=None): js = self.js_template % dict(picker_id=picker_id, options=json.dumps(self.options or {})) else: js = '' - return mark_safe(force_text(html + js)) + return mark_safe(force_str(html + js)) diff --git a/tests/legacy.py b/tests/legacy.py new file mode 100644 index 0000000..f9d7aad --- /dev/null +++ b/tests/legacy.py @@ -0,0 +1,16 @@ +import django + +from bootstrap3_datetime.widgets import DateTimePicker + + +class DateTimePickerDjango110(DateTimePicker): + def build_attrs(self, base_attrs=None, extra_attrs=None, **kwargs): + if extra_attrs: + base_attrs.update(extra_attrs) + base_attrs.update(kwargs) + return super(DateTimePickerDjango110, self).build_attrs(**base_attrs) + + +def is_legacy(): + x,y,z = [int(v) for v in django.__version__.split(".")] + return x == 1 and y < 11 diff --git a/tests/test_widgets.py b/tests/test_widgets.py new file mode 100644 index 0000000..0dc8512 --- /dev/null +++ b/tests/test_widgets.py @@ -0,0 +1,12 @@ +import json + +from legacy import DateTimePickerDjango110, is_legacy + +from bootstrap3_datetime.widgets import DateTimePicker + + +def test_rendering(): + options = {"pickTime": True, "format": "YYYY-MM-DD HH:mm"} + widget = (DateTimePickerDjango110 if is_legacy() else DateTimePicker)(options=options) + expected_output = '\n