Python django.forms.Textarea() Examples
The following are 30
code examples of django.forms.Textarea().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.forms
, or try the search function
.
Example #1
Source File: forms.py From freedomvote with GNU General Public License v3.0 | 7 votes |
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, })
Example #2
Source File: text.py From coursys with GNU General Public License v3.0 | 7 votes |
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', '15')}), 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
Example #3
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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) )
Example #4
Source File: test_cluster_form.py From django-modelcluster with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #5
Source File: test_edit_handlers.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #6
Source File: forms.py From janeway with GNU Affero General Public License v3.0 | 6 votes |
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
Example #7
Source File: text.py From coursys with GNU General Public License v3.0 | 6 votes |
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
Example #8
Source File: markup.py From coursys with GNU General Public License v3.0 | 6 votes |
def __init__(self): widgets = ( forms.Textarea(attrs={'cols': 70, 'rows': 20}), forms.Select(), forms.CheckboxInput(), ) super(MarkupContentWidget, self).__init__(widgets)
Example #9
Source File: forms_json.py From starthinker with Apache License 2.0 | 6 votes |
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)
Example #10
Source File: test_cluster_form.py From django-modelcluster with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #11
Source File: helper.py From DCRM with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #12
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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})])
Example #13
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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) )
Example #14
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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})])
Example #15
Source File: forms.py From colossus with MIT License | 5 votes |
def __init__(self, email=None, *args, **kwargs): super().__init__(*args, **kwargs) self.email = email blocks = email.get_blocks() for block_key, block_content in blocks.items(): self.fields[block_key] = forms.CharField( label=_('Block %s' % block_key), required=False, initial=block_content, widget=forms.Textarea() )
Example #16
Source File: djangoforms.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def get_form_field(self, **kwargs): """Return a Django form field appropriate for a StringList property. This defaults to a Textarea widget with a blank initial value. """ defaults = {'widget': forms.Textarea, 'initial': ''} defaults.update(kwargs) return super(StringListProperty, self).get_form_field(**defaults)
Example #17
Source File: mail.py From helfertool with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super(MailForm, self).__init__(*args, **kwargs) self.languages = self._get_languages() self.fields['language'] = forms.ChoiceField( choices=self.languages, label=_("Language"), ) self.fields['language'].widget.attrs['onChange'] = 'handle_lang()' self.fields['english'] = forms.BooleanField( label=_("Add English text"), initial=True, required=False, ) self.fields['english'].widget.attrs['onChange'] = 'handle_lang()' self.fields['subject'] = forms.CharField( label=_("Subject"), max_length=200, ) self.fields["text"] = forms.CharField( widget=forms.Textarea, label=_("Text"), ) self.fields["text_en"] = forms.CharField( widget=forms.Textarea, label=_("English text"), required=False, # will be checked in clean )
Example #18
Source File: admin.py From jorvik with GNU General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(ArticoloAdminForm, self).__init__(*args, **kwargs) self.fields['estratto'].widget = forms.Textarea() self.fields['estratto'].help_text = 'L\'estratto è limitato a 1024 caratteri, il testo eccedente sarà tagliato'
Example #19
Source File: comment.py From eoj3 with MIT License | 5 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['name'] = forms.CharField(widget=forms.HiddenInput) self.fields['email'] = forms.CharField(widget=forms.HiddenInput) self.fields['url'] = forms.CharField(widget=forms.HiddenInput) self.fields['honeypot'] = forms.CharField(widget=forms.HiddenInput) self.fields['followup'] = forms.BooleanField(widget=forms.HiddenInput) self.fields['comment'].widget = forms.Textarea(attrs={'class': 'markdown'}) self.fields['comment'].label = ''
Example #20
Source File: forms.py From djangocms-forms with BSD 3-Clause "New" or "Revised" License | 5 votes |
def prepare_textarea(self, field): field_attrs = field.build_field_attrs() widget_attrs = field.build_widget_attrs() field_attrs.update({ 'widget': forms.Textarea(attrs=widget_attrs) }) return forms.CharField(**field_attrs)
Example #21
Source File: forms.py From mooder with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(ProfileForm, self).__init__(*args, **kwargs) self['mugshot'].field.widget = forms.FileInput() self['description'].field.widget = forms.Textarea(attrs={'rows': 3})
Example #22
Source File: __init__.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def formfield(self, **kwargs): defaults = {'widget': forms.Textarea} defaults.update(kwargs) return super(TextField, self).formfield(**defaults)
Example #23
Source File: djangoforms.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def get_form_field(self, **kwargs): """Return a Django form field appropriate for a text property. This sets the widget default to forms.Textarea. """ defaults = {'widget': forms.Textarea} defaults.update(kwargs) return super(TextProperty, self).get_form_field(**defaults)
Example #24
Source File: djangoforms.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def get_form_field(self, **kwargs): """Return a Django form field appropriate for a string property. This sets the widget default to forms.Textarea if the property's multiline attribute is set. """ defaults = {} if self.multiline: defaults['widget'] = forms.Textarea defaults.update(kwargs) return super(StringProperty, self).get_form_field(**defaults)
Example #25
Source File: fields.py From callisto-core with GNU Affero General Public License v3.0 | 5 votes |
def textarea(cls, question): return forms.CharField( required=False, label=mark_safe(question.text), help_text=mark_safe(question.descriptive_text), widget=forms.Textarea, )
Example #26
Source File: forms.py From connect with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, *args, **kwargs): self.user = kwargs.pop('user', None) super(ProfileForm, self).__init__(*args, **kwargs) self.fields['full_name'] = forms.CharField( max_length=30, initial=self.user.full_name, widget=forms.TextInput(attrs={ 'placeholder': _('Name'), }), error_messages={ 'required': _('Please enter your full name.') }) self.fields['bio'] = forms.CharField( initial=self.user.bio, widget=forms.Textarea(attrs={ 'class': 'bio', 'placeholder': _('Add some details about yourself...'), 'rows': 'auto', }), required=False) roles = Role.objects.all() self.fields['roles'] = RoleModelMultipleChoiceField( initial=self.user.roles.all(), queryset=roles, widget=forms.CheckboxSelectMultiple(), required=False)
Example #27
Source File: __init__.py From python2017 with MIT License | 5 votes |
def formfield(self, **kwargs): # Passing max_length to forms.CharField means that the value's length # will be validated twice. This is considered acceptable since we want # the value in the form field (to pass into widget for example). defaults = {'max_length': self.max_length, 'widget': forms.Textarea} defaults.update(kwargs) return super(TextField, self).formfield(**defaults)
Example #28
Source File: jsonb.py From openhgsenti with Apache License 2.0 | 5 votes |
def __init__(self, **kwargs): kwargs.setdefault('widget', forms.Textarea) super(JSONField, self).__init__(**kwargs)
Example #29
Source File: __init__.py From openhgsenti with Apache License 2.0 | 5 votes |
def formfield(self, **kwargs): # Passing max_length to forms.CharField means that the value's length # will be validated twice. This is considered acceptable since we want # the value in the form field (to pass into widget for example). defaults = {'max_length': self.max_length, 'widget': forms.Textarea} defaults.update(kwargs) return super(TextField, self).formfield(**defaults)
Example #30
Source File: field_block.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, required=True, help_text=None, max_length=None, min_length=None, validators=(), **kwargs): self.field = forms.CharField( required=required, help_text=help_text, max_length=max_length, min_length=min_length, validators=validators, widget=forms.Textarea) super().__init__(**kwargs)