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


Python forms.Textarea方法代码示例

本文整理汇总了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 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:text.py

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

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

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

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

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

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

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

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

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

示例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',
        ) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:38,代码来源:forms.py

示例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 
开发者ID:sfu-fas,项目名称:coursys,代码行数:14,代码来源:text.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:6,代码来源:gittag.py

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

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


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