当前位置: 首页>>代码示例>>Python>>正文


Python forms.TimeField方法代码示例

本文整理汇总了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") 
开发者ID:nesdis,项目名称:djongo,代码行数:26,代码来源:test_input_formats.py

示例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") 
开发者ID:nesdis,项目名称:djongo,代码行数:26,代码来源:test_input_formats.py

示例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") 
开发者ID:nesdis,项目名称:djongo,代码行数:24,代码来源:test_input_formats.py

示例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") 
开发者ID:nesdis,项目名称:djongo,代码行数:24,代码来源:test_input_formats.py

示例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") 
开发者ID:nesdis,项目名称:djongo,代码行数:24,代码来源:test_input_formats.py

示例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") 
开发者ID:nesdis,项目名称:djongo,代码行数:26,代码来源:test_input_formats.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:9,代码来源:__init__.py

示例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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:__init__.py

示例9: get_internal_type

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TimeField [as 别名]
def get_internal_type(self):
        return "TimeField" 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:4,代码来源:__init__.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:9,代码来源:__init__.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:5,代码来源:__init__.py

示例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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:6,代码来源:__init__.py

示例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,
        }) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:7,代码来源:__init__.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:7,代码来源:field_block.py


注:本文中的django.forms.TimeField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。