本文整理匯總了Python中django.forms.SplitDateTimeField方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.SplitDateTimeField方法的具體用法?Python forms.SplitDateTimeField怎麽用?Python forms.SplitDateTimeField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.forms
的用法示例。
在下文中一共展示了forms.SplitDateTimeField方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_form_fields
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import SplitDateTimeField [as 別名]
def _get_form_fields(self):
return OrderedDict(
(
(self.lookup_kwarg_gte, forms.SplitDateTimeField(
label='',
widget=AdminSplitDateTime(attrs={'placeholder': _('From date')}),
localize=True,
required=False,
initial=self.default_gte,
)),
(self.lookup_kwarg_lte, forms.SplitDateTimeField(
label='',
widget=AdminSplitDateTime(attrs={'placeholder': _('To date')}),
localize=True,
required=False,
initial=self.default_lte,
)),
)
)
示例2: test_default_splitdatetime_field
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import SplitDateTimeField [as 別名]
def test_default_splitdatetime_field(self):
class PubForm(forms.ModelForm):
datetime_published = forms.SplitDateTimeField(required=False)
class Meta:
model = PublicationDefaults
fields = ('datetime_published',)
mf1 = PubForm({})
self.assertEqual(mf1.errors, {})
m1 = mf1.save(commit=False)
self.assertEqual(m1.datetime_published, datetime.datetime(2000, 1, 1))
mf2 = PubForm({'datetime_published_0': '2010-01-01', 'datetime_published_1': '0:00:00'})
self.assertEqual(mf2.errors, {})
m2 = mf2.save(commit=False)
self.assertEqual(m2.datetime_published, datetime.datetime(2010, 1, 1))
示例3: test_splitdatetimefield_1
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import SplitDateTimeField [as 別名]
def test_splitdatetimefield_1(self):
f = SplitDateTimeField()
self.assertIsInstance(f.widget, SplitDateTimeWidget)
self.assertEqual(
datetime.datetime(2006, 1, 10, 7, 30),
f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)])
)
with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None)
with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('')
with self.assertRaisesMessage(ValidationError, "'Enter a list of values.'"):
f.clean('hello')
with self.assertRaisesMessage(ValidationError, "'Enter a valid date.', 'Enter a valid time.'"):
f.clean(['hello', 'there'])
with self.assertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(['2006-01-10', 'there'])
with self.assertRaisesMessage(ValidationError, "'Enter a valid date.'"):
f.clean(['hello', '07:30'])
示例4: test_splitdatetimefield_2
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import SplitDateTimeField [as 別名]
def test_splitdatetimefield_2(self):
f = SplitDateTimeField(required=False)
self.assertEqual(
datetime.datetime(2006, 1, 10, 7, 30),
f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)])
)
self.assertEqual(datetime.datetime(2006, 1, 10, 7, 30), f.clean(['2006-01-10', '07:30']))
self.assertIsNone(f.clean(None))
self.assertIsNone(f.clean(''))
self.assertIsNone(f.clean(['']))
self.assertIsNone(f.clean(['', '']))
with self.assertRaisesMessage(ValidationError, "'Enter a list of values.'"):
f.clean('hello')
with self.assertRaisesMessage(ValidationError, "'Enter a valid date.', 'Enter a valid time.'"):
f.clean(['hello', 'there'])
with self.assertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(['2006-01-10', 'there'])
with self.assertRaisesMessage(ValidationError, "'Enter a valid date.'"):
f.clean(['hello', '07:30'])
with self.assertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(['2006-01-10', ''])
with self.assertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(['2006-01-10'])
with self.assertRaisesMessage(ValidationError, "'Enter a valid date.'"):
f.clean(['', '07:30'])
示例5: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import SplitDateTimeField [as 別名]
def __init__(self, request, *args, **kwargs):
field_name = kwargs.pop('field_name')
super(DateTimeFilterForm, self).__init__(*args, **kwargs)
self.request = request
self.fields['%s_as_of' % field_name] = forms.SplitDateTimeField(
label='',
input_time_formats=['%I:%M %p', '%H:%M:%S'],
widget=AdminSplitDateTime(
attrs={'placeholder': 'as of date and time'}
),
localize=True,
required=True
)
示例6: test_splitdatetimefield_changed
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import SplitDateTimeField [as 別名]
def test_splitdatetimefield_changed(self):
f = SplitDateTimeField(input_date_formats=['%d/%m/%Y'])
self.assertFalse(f.has_changed(['11/01/2012', '09:18:15'], ['11/01/2012', '09:18:15']))
self.assertTrue(f.has_changed(datetime.datetime(2008, 5, 6, 12, 40, 00), ['2008-05-06', '12:40:00']))
self.assertFalse(f.has_changed(datetime.datetime(2008, 5, 6, 12, 40, 00), ['06/05/2008', '12:40']))
self.assertTrue(f.has_changed(datetime.datetime(2008, 5, 6, 12, 40, 00), ['06/05/2008', '12:41']))
示例7: test_using_split_datetime_widget
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import SplitDateTimeField [as 別名]
def test_using_split_datetime_widget(self):
class SplitDateTimeRangeField(pg_forms.DateTimeRangeField):
base_field = forms.SplitDateTimeField
class SplitForm(forms.Form):
field = SplitDateTimeRangeField()
form = SplitForm()
self.assertHTMLEqual(str(form), '''
<tr>
<th>
<label for="id_field_0">Field:</label>
</th>
<td>
<input id="id_field_0_0" name="field_0_0" type="text">
<input id="id_field_0_1" name="field_0_1" type="text">
<input id="id_field_1_0" name="field_1_0" type="text">
<input id="id_field_1_1" name="field_1_1" type="text">
</td>
</tr>
''')
form = SplitForm({
'field_0_0': '01/01/2014',
'field_0_1': '00:00:00',
'field_1_0': '02/02/2014',
'field_1_1': '12:12:12',
})
self.assertTrue(form.is_valid())
lower = datetime.datetime(2014, 1, 1, 0, 0, 0)
upper = datetime.datetime(2014, 2, 2, 12, 12, 12)
self.assertEqual(form.cleaned_data['field'], DateTimeTZRange(lower, upper))