def _get_form_fields(self): return OrderedDict(( (self.lookup_kwarg_gte, forms.DateTimeField(label='', widget=widgets.AdminDateTimeInput( attrs={'placeholder': _('From date')}), localize=True, required=False)), (self.lookup_kwarg_lte, forms.DateTimeField(label='', widget=widgets.AdminDateTimeInput( attrs={'placeholder': _('To date')}), localize=True, required=False)), ))
def test_render_js_init_with_format_from_settings(self): widget = widgets.AdminDateTimeInput() html = widget.render('test', None, attrs={'id': 'test-id'}) self.assertIn( '"format": "d.m.Y. H:i"', html, )
def test_render_js_init_with_format(self): widget = widgets.AdminDateTimeInput(format='%d.%m.%Y. %H:%M') html = widget.render('test', None, attrs={'id': 'test-id'}) self.assertIn( '"format": "d.m.Y. H:i"', html, )
def test_render_js_init_with_format_from_settings(self): widget = widgets.AdminDateTimeInput() js_init = widget.render_js_init('test-id', 'test', None) self.assertIn( '"format": "d.m.Y. H:i"', js_init, )
def test_render_js_init_with_format(self): widget = widgets.AdminDateTimeInput(format='%d.%m.%Y. %H:%M') js_init = widget.render_js_init('test-id', 'test', None) self.assertIn( '"format": "d.m.Y. H:i"', js_init, )
def test_adapt(self): widget = widgets.AdminDateTimeInput() js_args = widgets.AdminDateTimeInputAdapter().js_args(widget) self.assertEqual( js_args[0], {"dayOfWeekStart": 0, "format": "Y-m-d H:i", "formatTime": "H:i"}, )
def test_adapt(self): widget = widgets.AdminDateTimeInput() js_args = widgets.AdminDateTimeInputAdapter().js_args(widget) self.assertEqual(js_args[0], { 'dayOfWeekStart': 0, 'format': 'Y-m-d H:i', 'formatTime': 'H:i' })
def test_adapt_with_custom_format(self): widget = widgets.AdminDateTimeInput( format="%d.%m.%Y. %H:%M", time_format="%H:%M %p" ) js_args = widgets.AdminDateTimeInputAdapter().js_args(widget) self.assertEqual( js_args[0], {"dayOfWeekStart": 0, "format": "d.m.Y. H:i", "formatTime": "H:i A"}, )
def test_render_js_init(self): widget = widgets.AdminDateTimeInput() js_init = widget.render_js_init('test-id', 'test', None) # we should see the JS initialiser code: # initDateTimeChooser("test-id", {"dayOfWeekStart": 0, "format": "Y-m-d H:i"}); # except that we can't predict the order of the config options self.assertIn('initDateTimeChooser("test-id", {', js_init) self.assertIn('"dayOfWeekStart": 0', js_init) self.assertIn('"format": "Y-m-d H:i"', js_init)
def test_adapt_with_custom_format(self): widget = widgets.AdminDateTimeInput(format='%d.%m.%Y. %H:%M', time_format='%H:%M %p') js_args = widgets.AdminDateTimeInputAdapter().js_args(widget) self.assertEqual(js_args[0], { 'dayOfWeekStart': 0, 'format': 'd.m.Y. H:i', 'formatTime': 'H:i A' })
def test_render_js_init_with_format_from_settings(self): widget = widgets.AdminDateTimeInput() html = widget.render("test", None, attrs={"id": "test-id"}) self.assertIn( '"format": "d.m.Y. H:i"', html, ) self.assertIn( '"formatTime": "H:i A"', html, )
def test_render_js_init_with_format(self): widget = widgets.AdminDateTimeInput(format="%d.%m.%Y. %H:%M", time_format="%H:%M %p") html = widget.render("test", None, attrs={"id": "test-id"}) self.assertIn( '"format": "d.m.Y. H:i"', html, ) self.assertIn( '"formatTime": "H:i A"', html, )
def test_render_js_init(self): widget = widgets.AdminDateTimeInput() html = widget.render('test', None, attrs={'id': 'test-id'}) self.assertInHTML('<input type="text" name="test" autocomplete="off" id="test-id" />', html) # we should see the JS initialiser code: # initDateTimeChooser("test-id", {"dayOfWeekStart": 0, "format": "Y-m-d H:i"}); # except that we can't predict the order of the config options self.assertIn('initDateTimeChooser("test\\u002Did", {', html) self.assertIn('"dayOfWeekStart": 0', html) self.assertIn('"format": "Y-m-d H:i"', html)