Python django.contrib.admin.widgets.AdminSplitDateTime() Examples

The following are 6 code examples of django.contrib.admin.widgets.AdminSplitDateTime(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.contrib.admin.widgets , or try the search function .
Example #1
Source File: admin.py    From cleanerversion with Apache License 2.0 6 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        field_name = kwargs.pop('field_name')
        super(DateTimeFilterForm, self).__init__(*args, **kwargs)
        self.request = request
        self.fields['%s_as_of' % field_name] = forms.SplitDateTimeField(
            label='',
            input_time_formats=['%I:%M %p', '%H:%M:%S'],
            widget=AdminSplitDateTime(
                attrs={'placeholder': 'as of date and time'}
            ),
            localize=True,
            required=True
        ) 
Example #2
Source File: tests.py    From celery-monitor with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
            class TestForm(forms.Form):
                char = forms.CharField(max_length=255)
                hidden = forms.CharField(max_length=255, widget=forms.HiddenInput())
                date = forms.DateField(widget=AdminDateWidget())
                datetime = forms.DateTimeField(widget=AdminSplitDateTime())

            self.form = TestForm({
                'char': 'hi there',
                'hidden': 'hidden text',
                'date': '20140111',
            }) 
Example #3
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_DateTimeField(self):
        self.assertFormfield(Member, 'birthdate', widgets.AdminSplitDateTime) 
Example #4
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_formfield_overrides_for_datetime_field(self):
        """
        Overriding the widget for DateTimeField doesn't overrides the default
        form_class for that field (#26449).
        """
        class MemberAdmin(admin.ModelAdmin):
            formfield_overrides = {DateTimeField: {'widget': widgets.AdminSplitDateTime}}
        ma = MemberAdmin(Member, admin.site)
        f1 = ma.formfield_for_dbfield(Member._meta.get_field('birthdate'), request=None)
        self.assertIsInstance(f1.widget, widgets.AdminSplitDateTime)
        self.assertIsInstance(f1, forms.SplitDateTimeField) 
Example #5
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_render(self):
        w = widgets.AdminSplitDateTime()
        self.assertHTMLEqual(
            w.render('test', datetime(2007, 12, 1, 9, 30)),
            '<p class="datetime">'
            'Date: <input value="2007-12-01" type="text" class="vDateField" '
            'name="test_0" size="10"><br>'
            'Time: <input value="09:30:00" type="text" class="vTimeField" '
            'name="test_1" size="8"></p>'
        ) 
Example #6
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_localization(self):
        w = widgets.AdminSplitDateTime()

        with self.settings(USE_L10N=True), translation.override('de-at'):
            w.is_localized = True
            self.assertHTMLEqual(
                w.render('test', datetime(2007, 12, 1, 9, 30)),
                '<p class="datetime">'
                'Datum: <input value="01.12.2007" type="text" '
                'class="vDateField" name="test_0"size="10"><br>'
                'Zeit: <input value="09:30:00" type="text" class="vTimeField" '
                'name="test_1" size="8"></p>'
            )