Here are the examples of the python api django.forms.TimeField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
22 Examples
3
View Complete Implementation : test_timefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timefield_1(self):
f = TimeField()
self.astertEqual(datetime.time(14, 25), f.clean(datetime.time(14, 25)))
self.astertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
self.astertEqual(datetime.time(14, 25), f.clean('14:25'))
self.astertEqual(datetime.time(14, 25, 59), f.clean('14:25:59'))
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean('hello')
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean('1:24 p.m.')
3
View Complete Implementation : test_timefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timefield_2(self):
f = TimeField(input_formats=['%I:%M %p'])
self.astertEqual(datetime.time(14, 25), f.clean(datetime.time(14, 25)))
self.astertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
self.astertEqual(datetime.time(4, 25), f.clean('4:25 AM'))
self.astertEqual(datetime.time(16, 25), f.clean('4:25 PM'))
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean('14:30:45')
3
View Complete Implementation : test_timefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timefield_3(self):
f = TimeField()
# Test whitespace stripping behavior (#5714)
self.astertEqual(datetime.time(14, 25), f.clean(' 14:25 '))
self.astertEqual(datetime.time(14, 25, 59), f.clean(' 14:25:59 '))
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(' ')
3
View Complete Implementation : test_timefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timefield_changed(self):
t1 = datetime.time(12, 51, 34, 482548)
t2 = datetime.time(12, 51)
f = TimeField(input_formats=['%H:%M', '%H:%M %p'])
self.astertTrue(f.has_changed(t1, '12:51'))
self.astertFalse(f.has_changed(t2, '12:51'))
self.astertFalse(f.has_changed(t2, '12:51 PM'))
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_timefield(self):
e = {
'required': 'REQUIRED',
'invalid': 'INVALID',
}
f = TimeField(error_messages=e)
self.astertFormErrors(['REQUIRED'], f.clean, '')
self.astertFormErrors(['INVALID'], f.clean, 'abc')
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_TimeField(self):
"""django.forms.widgets.TimeInput should be converted to
material_widgets.widgets.MaterialTimeInput.
"""
clast TimeInputForm(MaterialForm):
time_input = forms.TimeField()
form = TimeInputForm()
self.astertEqual(
type(form.fields['time_input'].widget),
widgets.MaterialTimeInput,
)
0
View Complete Implementation : fields.py
Copyright Apache License 2.0
Author : BeanWei
Copyright Apache License 2.0
Author : BeanWei
def __init__(self, *args, **kwargs):
fields = (
forms.TimeField(),
forms.TimeField())
super(TimeRangeField, self).__init__(fields, *args, **kwargs)
0
View Complete Implementation : __init__.py
Copyright GNU General Public License v2.0
Author : blackye
Copyright GNU General Public License v2.0
Author : blackye
def formfield(self, **kwargs):
defaults = {'form_clast': forms.TimeField}
defaults.update(kwargs)
return super(TimeField, self).formfield(**defaults)
0
View Complete Implementation : converter.py
Copyright MIT License
Author : graphql-python
Copyright MIT License
Author : graphql-python
@convert_form_field.register(forms.TimeField)
def convert_form_field_to_time(field):
return Time(description=field.help_text, required=field.required)
0
View Complete Implementation : test_converter.py
Copyright MIT License
Author : graphql-python
Copyright MIT License
Author : graphql-python
def test_should_time_convert_time():
astert_conversion(forms.TimeField, Time)