本文整理匯總了Python中django.forms.DateInput方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.DateInput方法的具體用法?Python forms.DateInput怎麽用?Python forms.DateInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.forms
的用法示例。
在下文中一共展示了forms.DateInput方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DateInput [as 別名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for name, field in self.fields.items():
if isinstance(field, forms.DateField):
# Force date format on load, so date picker doesn't mess it up
# because of i10n.
field.widget = forms.DateInput(format='%Y-%m-%d')
if name == 'extra':
field.label = getattr(
settings, 'USER_EXTRA_FIELD_LABEL', _('Additional data'))
示例2: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DateInput [as 別名]
def __init__(self, *args, **kwargs):
settings = kwargs.pop('settings', None)
super(GeneratedPluginSettingForm, self).__init__(*args, **kwargs)
for field in settings:
object = field['object']
if field['types'] == 'char':
self.fields[field['name']] = forms.CharField(widget=forms.TextInput(), required=False)
elif field['types'] == 'rich-text' or field['types'] == 'text' or field['types'] == 'Text':
self.fields[field['name']] = forms.CharField(widget=forms.Textarea, required=False)
elif field['types'] == 'json':
self.fields[field['name']] = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
choices=field['choices'],
required=False)
elif field['types'] == 'number':
self.fields[field['name']] = forms.CharField(widget=forms.TextInput(attrs={'type': 'number'}))
elif field['types'] == 'select':
self.fields[field['name']] = forms.CharField(widget=forms.Select(choices=field['choices']))
elif field['types'] == 'date':
self.fields[field['name']] = forms.CharField(
widget=forms.DateInput(attrs={'class': 'datepicker'}))
elif field['types'] == 'boolean':
self.fields[field['name']] = forms.BooleanField(
widget=forms.CheckboxInput(attrs={'is_checkbox': True}),
required=False)
self.fields[field['name']].initial = object.processed_value
self.fields[field['name']].help_text = object.setting.description
示例3: date_input
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DateInput [as 別名]
def date_input(field):
field.widget = DateInput()
field.widget.attrs.update({
'class': 'calendar-widget',
'data-role': 'data',
})
return field
示例4: test_date_input_different_format
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DateInput [as 別名]
def test_date_input_different_format(self):
"""
Tests that the ``django.forms`` configured input format is respected.
"""
class Form(forms.Form):
date = forms.DateField(widget=forms.DateInput(format='%m-%Y-%d'))
self.ctx['form'] = Form(initial={'date': datetime.date(2016, 3, 27)})
tmpl = get_template('widgets_django')
output = tmpl.render(self.ctx)
self.assertHTMLEqual(
output,
'<input type="text" name="date" id="id_date" value="03-2016-27" class=" " required>'
)
示例5: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DateInput [as 別名]
def __init__(self, attrs=None):
widgets = (forms.DateInput, forms.DateInput)
super().__init__(widgets, attrs)
示例6: test_format
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DateInput [as 別名]
def test_format(self):
"""
Use 'format' to change the way a value is displayed.
"""
d = date(2007, 9, 17)
widget = DateInput(format='%d/%m/%Y', attrs={'type': 'date'})
self.check_html(widget, 'date', d, html='<input type="date" name="date" value="17/09/2007">')
示例7: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DateInput [as 別名]
def __init__(self, *args, **kwargs):
elements = kwargs.pop('additional_fields', None)
super(PreprintInfo, self).__init__(*args, **kwargs)
self.fields['license'].queryset = submission_models.Licence.objects.filter(press__isnull=False,
available_for_submission=True)
self.fields['license'].required = True
# If there is an instance, we want to try to set the default subject area
if 'instance' in kwargs:
article = kwargs['instance']
if article:
self.fields['subject'].initial = article.get_subject_area()
if elements:
for element in elements:
if element.kind == 'text':
self.fields[element.name] = forms.CharField(
widget=forms.TextInput(attrs={'div_class': element.width}),
required=element.required)
elif element.kind == 'textarea':
self.fields[element.name] = forms.CharField(widget=forms.Textarea,
required=element.required)
elif element.kind == 'date':
self.fields[element.name] = forms.CharField(
widget=forms.DateInput(attrs={'class': 'datepicker', 'div_class': element.width}),
required=element.required)
elif element.kind == 'select':
choices = render_choices(element.choices)
self.fields[element.name] = forms.ChoiceField(
widget=forms.Select(attrs={'div_class': element.width}), choices=choices,
required=element.required)
elif element.kind == 'email':
self.fields[element.name] = forms.EmailField(
widget=forms.TextInput(attrs={'div_class': element.width}),
required=element.required)
elif element.kind == 'check':
self.fields[element.name] = forms.BooleanField(
widget=forms.CheckboxInput(attrs={'is_checkbox': True}),
required=element.required)
self.fields[element.name].help_text = element.help_text
self.fields[element.name].label = element.name
if article:
try:
check_for_answer = submission_models.FieldAnswer.objects.get(field=element, article=article)
self.fields[element.name].initial = check_for_answer.answer
except submission_models.FieldAnswer.DoesNotExist:
pass
示例8: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DateInput [as 別名]
def __init__(self, *args, **kwargs):
review_assignment = kwargs.pop('review_assignment', None)
fields_required = kwargs.pop('fields_required', True)
answer = kwargs.pop('answer', None)
preview = kwargs.pop('preview', None)
super(GeneratedForm, self).__init__(*args, **kwargs)
if answer:
elements = [answer.element]
elif preview:
elements = preview.elements.all()
else:
elements = review_assignment.form.elements.all()
for element in elements:
if element.kind == 'text':
self.fields[element.name] = forms.CharField(
widget=forms.TextInput(attrs={'div_class': element.width}),
required=element.required if fields_required else False)
elif element.kind == 'textarea':
self.fields[element.name] = forms.CharField(widget=forms.Textarea,
required=element.required if fields_required else False)
elif element.kind == 'date':
self.fields[element.name] = forms.CharField(
widget=forms.DateInput(attrs={'class': 'datepicker', 'div_class': element.width}),
required=element.required if fields_required else False)
elif element.kind == 'upload':
self.fields[element.name] = forms.FileField(required=element.required if fields_required else False)
elif element.kind == 'select':
choices = render_choices(element.choices)
self.fields[element.name] = forms.ChoiceField(
widget=forms.Select(attrs={'div_class': element.width}), choices=choices,
required=element.required if fields_required else False)
elif element.kind == 'email':
self.fields[element.name] = forms.EmailField(
widget=forms.TextInput(attrs={'div_class': element.width}),
required=element.required if fields_required else False)
elif element.kind == 'check':
self.fields[element.name] = forms.BooleanField(
widget=forms.CheckboxInput(attrs={'is_checkbox': True}),
required=element.required if fields_required else False)
self.fields[element.name].help_text = element.help_text
self.fields[element.name].label = element.name
if answer:
self.fields[element.name].initial = answer.edited_answer if answer.edited_answer else answer.answer