本文整理汇总了Python中django.forms.TimeField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.TimeField方法的具体用法?Python forms.TimeField怎么用?Python forms.TimeField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms
的用法示例。
在下文中一共展示了forms.TimeField方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_timeField_with_inputformat
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def test_timeField_with_inputformat(self):
"TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"])
# Parse a time in an unaccepted format; get an error
with self.assertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
with self.assertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30.05')
self.assertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.assertEqual(text, "13:30:05")
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30')
self.assertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.assertEqual(text, "13:30:00")
示例2: test_localized_timeField_with_inputformat
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def test_localized_timeField_with_inputformat(self):
"Localized TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True)
# Parse a time in an unaccepted format; get an error
with self.assertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
with self.assertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30.05')
self.assertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.assertEqual(text, "13:30:05")
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30')
self.assertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.assertEqual(text, "13:30:00")
示例3: test_timeField
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def test_timeField(self):
"TimeFields can parse dates in the default format"
f = forms.TimeField()
# Parse a time in an unaccepted format; get an error
with self.assertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('1:30:05 PM')
self.assertEqual(result, time(13, 30, 5))
# The parsed result does a round trip
text = f.widget.format_value(result)
self.assertEqual(text, '01:30:05 PM')
# Parse a time in a valid, but non-default format, get a parsed result
result = f.clean('1:30 PM')
self.assertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.assertEqual(text, "01:30:00 PM")
示例4: test_localized_timeField
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def test_localized_timeField(self):
"Localized TimeFields act as unlocalized widgets"
f = forms.TimeField(localize=True)
# Parse a time in an unaccepted format; get an error
with self.assertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('1:30:05 PM')
self.assertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.assertEqual(text, '01:30:05 PM')
# Parse a time in a valid format, get a parsed result
result = f.clean('01:30 PM')
self.assertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.assertEqual(text, "01:30:00 PM")
示例5: test_localized_timeField
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def test_localized_timeField(self):
"Localized TimeFields act as unlocalized widgets"
f = forms.TimeField(localize=True)
# Parse a time in an unaccepted format; get an error
with self.assertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
# Parse a time in a valid format, get a parsed result
result = f.clean('13:30:05')
self.assertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.assertEqual(text, '13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('13:30')
self.assertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.assertEqual(text, "13:30:00")
示例6: test_localized_timeField_with_inputformat
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def test_localized_timeField_with_inputformat(self):
"Localized TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True)
# Parse a time in an unaccepted format; get an error
with self.assertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
with self.assertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30.05')
self.assertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.assertEqual(text, "01:30:05 PM")
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30')
self.assertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.assertEqual(text, "01:30:00 PM")
示例7: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def __init__(self, verbose_name=None, name=None, auto_now=False,
auto_now_add=False, **kwargs):
self.auto_now, self.auto_now_add = auto_now, auto_now_add
if auto_now or auto_now_add:
kwargs['editable'] = False
kwargs['blank'] = True
super(TimeField, self).__init__(verbose_name, name, **kwargs)
示例8: deconstruct
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def deconstruct(self):
name, path, args, kwargs = super(TimeField, self).deconstruct()
if self.auto_now is not False:
kwargs["auto_now"] = self.auto_now
if self.auto_now_add is not False:
kwargs["auto_now_add"] = self.auto_now_add
if self.auto_now or self.auto_now_add:
del kwargs['blank']
del kwargs['editable']
return name, path, args, kwargs
示例9: get_internal_type
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def get_internal_type(self):
return "TimeField"
示例10: pre_save
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def pre_save(self, model_instance, add):
if self.auto_now or (self.auto_now_add and add):
value = datetime.datetime.now().time()
setattr(model_instance, self.attname, value)
return value
else:
return super(TimeField, self).pre_save(model_instance, add)
示例11: get_prep_value
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def get_prep_value(self, value):
value = super(TimeField, self).get_prep_value(value)
return self.to_python(value)
示例12: formfield
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def formfield(self, **kwargs):
defaults = {'form_class': forms.TimeField}
defaults.update(kwargs)
return super().formfield(**defaults)
示例13: formfield
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def formfield(self, **kwargs):
return super().formfield(**{
'form_class': forms.TimeField,
**kwargs,
})
示例14: field
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def field(self):
from wagtail.admin.widgets import AdminTimeInput
field_kwargs = {'widget': AdminTimeInput}
field_kwargs.update(self.field_options)
return forms.TimeField(**field_kwargs)