當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。