class Widget
from django.forms import Widget
Ancestors (MRO)
- Widget
Descendants
- CheckboxInput
- CheckboxSelectMultiple
- ClearableFileInput
- DateInput
- DateTimeInput
- EmailInput
- FileInput
- HiddenInput
- MultiWidget
- MultipleHiddenInput
- NullBooleanSelect
- NumberInput
- PasswordInput
- RadioSelect
- Select
- SelectDateWidget
- SelectMultiple
- SplitDateTimeWidget
- SplitHiddenDateTimeWidget
- TextInput
- Textarea
- TimeInput
- URLInput
Attributes
Defined in | |
---|---|
is_localized = False
|
Widget |
is_required = False
|
Widget |
needs_multipart_form = False
|
Widget |
supports_microseconds = True
|
Widget |
Properties
def
is_hidden():
¶
Widget
def
media():
¶
Widget
Getter
def _media(self):
# Get the media property of the superclass, if it exists
sup_cls = super(cls, self)
try:
base = sup_cls.media
except AttributeError:
base = Media()
# Get the media definition for this class
definition = getattr(cls, 'Media', None)
if definition:
extend = getattr(definition, 'extend', True)
if extend:
if extend is True:
m = base
else:
m = Media()
for medium in extend:
m = m + base[medium]
return m + Media(definition)
else:
return Media(definition)
else:
return base
Methods
def
build_attrs(self, extra_attrs=None, **kwargs):
¶
Widget
Helper function for building an attribute dictionary.
def build_attrs(self, extra_attrs=None, **kwargs):
"Helper function for building an attribute dictionary."
attrs = dict(self.attrs, **kwargs)
if extra_attrs:
attrs.update(extra_attrs)
return attrs
def
id_for_label(self, id_):
¶
Widget
Returns the HTML ID attribute of this Widget for use by a <label>, given the ID of the field. Returns None if no ID is available. This hook is necessary because some widgets have multiple HTML elements and, thus, multiple IDs. In that case, this method should return an ID value that corresponds to the first ID in the widget's tags.
def id_for_label(self, id_):
"""
Returns the HTML ID attribute of this Widget for use by a <label>,
given the ID of the field. Returns None if no ID is available.
This hook is necessary because some widgets have multiple HTML
elements and, thus, multiple IDs. In that case, this method should
return an ID value that corresponds to the first ID in the widget's
tags.
"""
return id_
def
render(self, name, value, attrs=None):
¶
Widget
Returns this Widget rendered as HTML, as a Unicode string. The 'value' given is not guaranteed to be valid input, so subclass implementations should program defensively.
def render(self, name, value, attrs=None):
"""
Returns this Widget rendered as HTML, as a Unicode string.
The 'value' given is not guaranteed to be valid input, so subclass
implementations should program defensively.
"""
raise NotImplementedError('subclasses of Widget must provide a render() method')
def
subwidgets(self, name, value, attrs=None, choices=()):
¶
Widget
Yields all "subwidgets" of this widget. Used only by RadioSelect to allow template access to individual <input type="radio"> buttons. Arguments are the same as for render().
def subwidgets(self, name, value, attrs=None, choices=()):
"""
Yields all "subwidgets" of this widget. Used only by RadioSelect to
allow template access to individual <input type="radio"> buttons.
Arguments are the same as for render().
"""
yield SubWidget(self, name, value, attrs, choices)
def
use_required_attribute(self, initial):
¶
Widget
def use_required_attribute(self, initial):
return not self.is_hidden
def
value_from_datadict(self, data, files, name):
¶
Widget
Given a dictionary of data and this widget's name, returns the value of this widget. Returns None if it's not provided.
def value_from_datadict(self, data, files, name):
"""
Given a dictionary of data and this widget's name, returns the value
of this widget. Returns None if it's not provided.
"""
return data.get(name)
def
value_omitted_from_data(self, data, files, name):
¶
Widget
def value_omitted_from_data(self, data, files, name):
return name not in data