本文整理匯總了Python中django.forms.Textarea方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.Textarea方法的具體用法?Python forms.Textarea怎麽用?Python forms.Textarea使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.forms
的用法示例。
在下文中一共展示了forms.Textarea方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: make_entry_field
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def make_entry_field(self, fieldsubmission=None):
self.min_length = 0
self.max_length = 0
if self.config['min_length'] and int(self.config['min_length']) > 0:
self.min_length = int(self.config['min_length'])
if self.config['max_length'] and int(self.config['max_length']) > 0:
self.max_length = int(self.config['max_length'])
c = forms.CharField(required=self.config['required'],
widget=forms.Textarea(attrs={'cols': '60', 'rows': self.config.get('rows', '3')}),
label=self.config['label'],
help_text=self.config['help_text'],
min_length=self.min_length,
max_length=self.max_length)
if fieldsubmission:
c.initial = fieldsubmission.data['info']
return c
示例2: render_layout
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def render_layout(self, form, context, template_pack=TEMPLATE_PACK):
"""
Copy any field label to the ``placeholder`` attribute.
Note, this method is called when :attr:`layout` is defined.
"""
# Writing the label values into the field placeholders.
# This is done at rendering time, so the Form.__init__() could update any labels before.
# Django 1.11 no longer lets EmailInput or URLInput inherit from TextInput,
# so checking for `Input` instead while excluding `HiddenInput`.
for field in form.fields.values():
if field.label and \
isinstance(field.widget, (Input, forms.Textarea)) and \
not isinstance(field.widget, forms.HiddenInput):
field.widget.attrs['placeholder'] = u"{0}:".format(field.label)
return super(CompactLabelsCommentFormHelper, self).render_layout(form, context, template_pack=template_pack)
示例3: get_field_kind
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def get_field_kind(field):
if field['kind'] == 'string':
return forms.CharField(max_length=255, required=False)
elif field['kind'] == 'email':
return forms.EmailField(max_length=255, required=False)
elif field['kind'] == 'integer':
return forms.IntegerField(required=False)
elif field['kind'] == 'boolean':
return forms.BooleanField(required=False)
elif field['kind'] == 'text':
return forms.CharField(widget=forms.Textarea(), required=False)
elif field['kind'] == 'choice':
return forms.ChoiceField(choices=map(lambda c: (c,c), field['choices']))
elif field['kind'] == 'timezones':
return TimezoneField()
elif field['kind'] == 'authentication':
return SwitchField('user', 'service', required=True)
elif field['kind'] == 'json':
return JsonField(required=False)
elif field['kind'] == 'integer_list':
return CommaSeparatedIntegerField(required=False)
elif field['kind'] == 'string_list':
return CommaSeparatedCharField(required=False)
else:
return forms.CharField(max_length=255, required=False)
示例4: test_explicit_formset_dict
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def test_explicit_formset_dict(self):
class BandForm(ClusterForm):
class Meta:
model = Band
formsets = {
'albums': {'fields': ['name'], 'widgets': {'name': Textarea()}}
}
fields = ['name']
form = BandForm()
self.assertTrue(form.formsets.get('albums'))
self.assertFalse(form.formsets.get('members'))
self.assertTrue('albums' in form.as_p())
self.assertFalse('members' in form.as_p())
self.assertIn('name', form.formsets['albums'].forms[0].fields)
self.assertNotIn('release_date', form.formsets['albums'].forms[0].fields)
self.assertEqual(Textarea, type(form.formsets['albums'].forms[0]['name'].field.widget))
示例5: test_formfield_callback
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def test_formfield_callback(self):
def formfield_for_dbfield(db_field, **kwargs):
# a particularly stupid formfield_callback that just uses Textarea for everything
return CharField(widget=Textarea, **kwargs)
class BandFormWithFFC(ClusterForm):
formfield_callback = formfield_for_dbfield
class Meta:
model = Band
fields = ['name']
form = BandFormWithFFC()
self.assertEqual(Textarea, type(form['name'].field.widget))
self.assertEqual(Textarea, type(form.formsets['members'].forms[0]['name'].field.widget))
示例6: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def __init__(self, *args, **kwargs):
key_type = kwargs.pop('key_type', None)
value = kwargs.pop('value', None)
super(EditKey, self).__init__(*args, **kwargs)
if key_type == 'rich-text':
self.fields['value'].widget = SummernoteWidget()
elif key_type == 'boolean':
self.fields['value'].widget = forms.CheckboxInput()
elif key_type == 'integer':
self.fields['value'].widget = forms.TextInput(attrs={'type': 'number'})
elif key_type == 'file' or key_type == 'journalthumb':
self.fields['value'].widget = forms.FileInput()
elif key_type == 'text':
self.fields['value'].widget = forms.Textarea()
else:
self.fields['value'].widget.attrs['size'] = '100%'
self.fields['value'].initial = value
self.fields['value'].required = False
示例7: setUp
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def setUp(self):
self.request = RequestFactory().get('/')
user = AnonymousUser() # technically, Anonymous users cannot access the admin
self.request.user = user
# a custom tabbed interface for EventPage
self.event_page_tabbed_interface = TabbedInterface([
ObjectList([
FieldPanel('title', widget=forms.Textarea),
FieldPanel('date_from'),
FieldPanel('date_to'),
], heading='Event details', classname="shiny"),
ObjectList([
InlinePanel('speakers', label="Speakers"),
], heading='Speakers'),
]).bind_to(model=EventPage, request=self.request)
示例8: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def __init__(self, *args, **kwargs):
kwargs.setdefault('label_suffix', '')
super(PoliticianForm, self).__init__(*args, **kwargs)
for field_name, field in self.fields.items():
if isinstance(field.widget, forms.TextInput) or isinstance(field.widget, forms.Select) or isinstance(field.widget, forms.EmailInput):
field.widget.attrs.update({
'class': 'form-control'
})
if field_name == 'party':
field.choices = [('', '---------')]
field.choices += [
(p.id, p.name)
for p
in Party.objects.order_by('name')
]
if isinstance(field.widget, forms.Textarea):
field.widget.attrs.update({
'class': 'form-control',
'rows': 2,
})
示例9: test_custom_callback
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def test_custom_callback(self):
"""A custom formfield_callback is used if provided"""
callback_args = []
def callback(db_field, **kwargs):
callback_args.append((db_field, kwargs))
return db_field.formfield(**kwargs)
widget = forms.Textarea()
class BaseForm(forms.ModelForm):
class Meta:
model = Person
widgets = {'name': widget}
fields = "__all__"
modelform_factory(Person, form=BaseForm, formfield_callback=callback)
id_field, name_field = Person._meta.fields
self.assertEqual(callback_args, [(id_field, {}), (name_field, {'widget': widget})])
示例10: test_inherit_after_custom_callback
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def test_inherit_after_custom_callback(self):
def callback(db_field, **kwargs):
if isinstance(db_field, models.CharField):
return forms.CharField(widget=forms.Textarea)
return db_field.formfield(**kwargs)
class BaseForm(forms.ModelForm):
class Meta:
model = Person
fields = '__all__'
NewForm = modelform_factory(Person, form=BaseForm, formfield_callback=callback)
class InheritedForm(NewForm):
pass
for name in NewForm.base_fields:
self.assertEqual(
type(InheritedForm.base_fields[name].widget),
type(NewForm.base_fields[name].widget)
)
示例11: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def __init__(self, event=None, *args, **kwargs):
super(DonationEntryForm, self).__init__(*args, **kwargs)
minDonationAmount = (
event.minimumdonation if event is not None else Decimal('1.00')
)
self.fields['amount'] = forms.DecimalField(
decimal_places=2,
min_value=minDonationAmount,
max_value=Decimal('100000'),
label='Donation Amount (min ${0})'.format(minDonationAmount),
widget=tracker.widgets.NumberInput(
attrs={
'id': 'iDonationAmount',
'min': str(minDonationAmount),
'step': '0.01',
}
),
required=True,
)
self.fields['comment'] = forms.CharField(widget=forms.Textarea, required=False)
self.fields['requestedvisibility'] = forms.ChoiceField(
initial='CURR',
choices=models.Donation._meta.get_field('requestedvisibility').choices,
label='Name Visibility',
)
self.fields['requestedalias'] = forms.CharField(
max_length=32, label='Preferred Alias', required=False
)
self.fields['requestedemail'] = forms.EmailField(
max_length=128, label='Preferred Email', required=False
)
self.fields['requestedsolicitemail'] = forms.ChoiceField(
initial='CURR',
choices=models.Donation._meta.get_field('requestedsolicitemail').choices,
label='Charity Email Opt In',
)
示例12: get_entry_field
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def get_entry_field(self, questionanswer=None, student=None):
max_length = self.version.config.get('max_length', 10000)
lines = self.version.config.get('lines', 5)
if questionanswer:
initial = questionanswer.answer.get('data', '')
else:
initial = None
field = forms.CharField(required=False, max_length=max_length, initial=initial,
widget=forms.Textarea(attrs={'rows': lines, 'cols': 100}))
field.widget.attrs.update({'class': 'long-answer'})
return field
示例13: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def __init__(self, *args, **kwargs):
super(GitTag.ComponentForm, self).__init__(*args, **kwargs)
self.fields.__delitem__('specified_filename')
self.fields['description'].widget = forms.Textarea(attrs={'cols': 50, 'rows': 5})
示例14: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def __init__(self, *args, **kwargs):
self.widget = forms.Textarea(attrs={'cols': 70, 'rows': 20})
if 'help_text' not in kwargs:
kwargs['help_text'] = 'Page formatted in <a href="/docs/pages">WikiCreole markup</a>.' # hard-coded URL since this is evaluated before urls.py: could be reverse_lazy?
super(WikiField, self).__init__(*args, **kwargs)
示例15: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Textarea [as 別名]
def __init__(self):
widgets = (
forms.Textarea(attrs={'cols': 70, 'rows': 20}),
forms.Select(),
forms.CheckboxInput(),
)
super(MarkupContentWidget, self).__init__(widgets)