示例#1
0
 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)),
     ))
示例#2
0
    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,
        )
示例#3
0
    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,
        )
示例#4
0
    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,
        )
示例#5
0
    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,
        )
示例#6
0
    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'
        })
示例#8
0
    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"},
        )
示例#9
0
    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)
示例#10
0
    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'
        })
示例#11
0
    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,
        )
示例#12
0
    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,
        )
示例#13
0
    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)