Here are the examples of the python api django.forms.SplitDateTimeField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
8 Examples
3
View Complete Implementation : test_multivaluefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def __init__(self, **kwargs):
fields = (
CharField(),
MultipleChoiceField(choices=beatles),
SplitDateTimeField(),
)
super().__init__(fields, **kwargs)
3
View Complete Implementation : test_splitdatetimefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_splitdatetimefield_1(self):
f = SplitDateTimeField()
self.astertIsInstance(f.widget, SplitDateTimeWidget)
self.astertEqual(
datetime.datetime(2006, 1, 10, 7, 30),
f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)])
)
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None)
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('')
with self.astertRaisesMessage(ValidationError, "'Enter a list of values.'"):
f.clean('hello')
with self.astertRaisesMessage(ValidationError, "'Enter a valid date.', 'Enter a valid time.'"):
f.clean(['hello', 'there'])
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(['2006-01-10', 'there'])
with self.astertRaisesMessage(ValidationError, "'Enter a valid date.'"):
f.clean(['hello', '07:30'])
3
View Complete Implementation : test_splitdatetimefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_splitdatetimefield_changed(self):
f = SplitDateTimeField(input_date_formats=['%d/%m/%Y'])
self.astertFalse(f.has_changed(['11/01/2012', '09:18:15'], ['11/01/2012', '09:18:15']))
self.astertTrue(f.has_changed(datetime.datetime(2008, 5, 6, 12, 40, 00), ['2008-05-06', '12:40:00']))
self.astertFalse(f.has_changed(datetime.datetime(2008, 5, 6, 12, 40, 00), ['06/05/2008', '12:40']))
self.astertTrue(f.has_changed(datetime.datetime(2008, 5, 6, 12, 40, 00), ['06/05/2008', '12:41']))
3
View Complete Implementation : test_error_messages.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_splitdatetimefield(self):
e = {
'required': 'REQUIRED',
'invalid_date': 'INVALID DATE',
'invalid_time': 'INVALID TIME',
}
f = SplitDateTimeField(error_messages=e)
self.astertFormErrors(['REQUIRED'], f.clean, '')
self.astertFormErrors(['INVALID DATE', 'INVALID TIME'], f.clean, ['a', 'b'])
3
View Complete Implementation : test_multiwidget.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def __init__(self, required=True, widget=None, label=None, initial=None):
fields = (
CharField(),
MultipleChoiceField(choices=WidgetTest.beatles),
SplitDateTimeField(),
)
super().__init__(fields, required, widget, label, initial)
3
View Complete Implementation : test_forms.py
Copyright Apache License 2.0
Author : ooknosi
Copyright Apache License 2.0
Author : ooknosi
def test_MaterialForm_materializes_SplitDateTimeField(self):
"""django.forms.widgets.SplitDateTimeWidget should be converted to
material_widgets.widgets.MaterialSplitDateTimeWidget.
"""
clast SplitDateTimeInputForm(MaterialForm):
split_date_time_widget = forms.SplitDateTimeField()
form = SplitDateTimeInputForm()
self.astertEqual(
type(form.fields['split_date_time_widget'].widget),
widgets.MaterialSplitDateTimeWidget,
)
3
View Complete Implementation : filter.py
Copyright MIT License
Author : silentsokolov
Copyright MIT License
Author : silentsokolov
def _get_form_fields(self):
return OrderedDict(
(
(self.lookup_kwarg_gte, forms.SplitDateTimeField(
label='',
widget=AdminSplitDateTime(attrs={'placeholder': _('From date')}),
localize=True,
required=False
)),
(self.lookup_kwarg_lte, forms.SplitDateTimeField(
label='',
widget=AdminSplitDateTime(attrs={'placeholder': _('To date')}),
localize=True,
required=False
)),
)
)
0
View Complete Implementation : test_splitdatetimefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_splitdatetimefield_2(self):
f = SplitDateTimeField(required=False)
self.astertEqual(
datetime.datetime(2006, 1, 10, 7, 30),
f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)])
)
self.astertEqual(datetime.datetime(2006, 1, 10, 7, 30), f.clean(['2006-01-10', '07:30']))
self.astertIsNone(f.clean(None))
self.astertIsNone(f.clean(''))
self.astertIsNone(f.clean(['']))
self.astertIsNone(f.clean(['', '']))
with self.astertRaisesMessage(ValidationError, "'Enter a list of values.'"):
f.clean('hello')
with self.astertRaisesMessage(ValidationError, "'Enter a valid date.', 'Enter a valid time.'"):
f.clean(['hello', 'there'])
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(['2006-01-10', 'there'])
with self.astertRaisesMessage(ValidationError, "'Enter a valid date.'"):
f.clean(['hello', '07:30'])
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(['2006-01-10', ''])
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(['2006-01-10'])
with self.astertRaisesMessage(ValidationError, "'Enter a valid date.'"):
f.clean(['', '07:30'])