summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2025-07-22 20:41:41 -0700
committernessita <124304+nessita@users.noreply.github.com>2025-07-23 20:17:55 -0300
commit69a93a88edb56ba47f624dac7a21aacc47ea474f (patch)
treef57507a4435d032493cae40e06ecb254790b67b2 /django/forms
parent55b0cc21310b76ce4018dd793ba50556eaf0af06 (diff)
Refs #36500 -- Rewrapped long docstrings and block comments via a script.
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/boundfield.py12
-rw-r--r--django/forms/fields.py16
-rw-r--r--django/forms/forms.py20
-rw-r--r--django/forms/formsets.py8
-rw-r--r--django/forms/models.py39
-rw-r--r--django/forms/widgets.py10
6 files changed, 61 insertions, 44 deletions
diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py
index c0324d5c1d..f6b721c72a 100644
--- a/django/forms/boundfield.py
+++ b/django/forms/boundfield.py
@@ -114,7 +114,8 @@ class BoundField(RenderableFieldMixin):
def as_text(self, attrs=None, **kwargs):
"""
- Return a string of HTML for representing this as an <input type="text">.
+ Return a string of HTML for representing this as an <input
+ type="text">.
"""
return self.as_widget(TextInput(), attrs, **kwargs)
@@ -124,7 +125,8 @@ class BoundField(RenderableFieldMixin):
def as_hidden(self, attrs=None, **kwargs):
"""
- Return a string of HTML for representing this as an <input type="hidden">.
+ Return a string of HTML for representing this as an <input
+ type="hidden">.
"""
return self.as_widget(self.field.hidden_widget(), attrs, **kwargs)
@@ -181,7 +183,8 @@ class BoundField(RenderableFieldMixin):
)
# Only add the suffix if the label does not end in punctuation.
# Translators: If found as last label character, these punctuation
- # characters will prevent the default label_suffix to be appended to the label
+ # characters will prevent the default label_suffix to be appended to
+ # the label
if label_suffix and contents and contents[-1] not in _(":?.!"):
contents = format_html("{}{}", contents, label_suffix)
widget = self.field.widget
@@ -239,7 +242,8 @@ class BoundField(RenderableFieldMixin):
def auto_id(self):
"""
Calculate and return the ID attribute for this BoundField, if the
- associated Form has specified auto_id. Return an empty string otherwise.
+ associated Form has specified auto_id. Return an empty string
+ otherwise.
"""
auto_id = self.form.auto_id # Boolean or string
if auto_id and "%s" in str(auto_id):
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 04aa2039fd..182d63c9b4 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -126,15 +126,18 @@ class Field:
# help_text -- An optional string to use as "help text" for this Field.
# error_messages -- An optional dictionary to override the default
# messages that the field will raise.
- # show_hidden_initial -- Boolean that specifies if it is needed to render a
+ # show_hidden_initial -- Boolean that specifies if it is needed to
+ # render a
# hidden widget with initial value after widget.
# validators -- List of additional validators to use
# localize -- Boolean that specifies if the field should be localized.
- # disabled -- Boolean that specifies whether the field is disabled, that
+ # disabled -- Boolean that specifies whether the field is disabled,
+ # that
# is its widget is shown in the form but not editable.
# label_suffix -- Suffix to be added to the label. Overrides
# form's label_suffix.
- # bound_field_class -- BoundField class to use in Field.get_bound_field.
+ # bound_field_class -- BoundField class to use in
+ # Field.get_bound_field.
self.required, self.label, self.initial = required, label, initial
self.show_hidden_initial = show_hidden_initial
self.help_text = help_text
@@ -727,8 +730,8 @@ class ImageField(FileField):
from PIL import Image
- # We need to get a file object for Pillow. We might have a path or we might
- # have to read the data into memory.
+ # We need to get a file object for Pillow. We might have a path or we
+ # might have to read the data into memory.
if hasattr(data, "temporary_file_path"):
file = data.temporary_file_path()
else:
@@ -929,7 +932,8 @@ class TypedChoiceField(ChoiceField):
def _coerce(self, value):
"""
- Validate that the value can be coerced to the right type (if not empty).
+ Validate that the value can be coerced to the right type (if not
+ empty).
"""
if value == self.empty_value or value in self.empty_values:
return self.empty_value
diff --git a/django/forms/forms.py b/django/forms/forms.py
index d05bf4bb9e..760ba7b767 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -137,12 +137,12 @@ class BaseForm(RenderableFormMixin):
"""
Rearrange the fields according to field_order.
- field_order is a list of field names specifying the order. Append fields
- not included in the list in the default order for backward compatibility
- with subclasses not overriding field_order. If field_order is None,
- keep all fields in the order defined in the class. Ignore unknown
- fields in field_order to allow disabling fields in form subclasses
- without redefining ordering.
+ field_order is a list of field names specifying the order. Append
+ fields not included in the list in the default order for backward
+ compatibility with subclasses not overriding field_order. If
+ field_order is None, keep all fields in the order defined in the class.
+ Ignore unknown fields in field_order to allow disabling fields in form
+ subclasses without redefining ordering.
"""
if field_order is None:
return
@@ -367,10 +367,10 @@ class BaseForm(RenderableFormMixin):
def clean(self):
"""
- Hook for doing any extra form-wide cleaning after Field.clean() has been
- called on every field. Any ValidationError raised by this method will
- not be associated with a particular field; it will have a special-case
- association with the field named '__all__'.
+ Hook for doing any extra form-wide cleaning after Field.clean() has
+ been called on every field. Any ValidationError raised by this method
+ will not be associated with a particular field; it will have a
+ special-case association with the field named '__all__'.
"""
return self.cleaned_data
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index 94aebe4924..054cc0bc0a 100644
--- a/django/forms/formsets.py
+++ b/django/forms/formsets.py
@@ -307,10 +307,10 @@ class BaseFormSet(RenderableFormMixin):
raise AttributeError(
"'%s' object has no attribute 'ordered_forms'" % self.__class__.__name__
)
- # Construct _ordering, which is a list of (form_index, order_field_value)
- # tuples. After constructing this list, we'll sort it by order_field_value
- # so we have a way to get to the form indexes in the order specified
- # by the form data.
+ # Construct _ordering, which is a list of (form_index,
+ # order_field_value) tuples. After constructing this list, we'll sort
+ # it by order_field_value so we have a way to get to the form indexes
+ # in the order specified by the form data.
if not hasattr(self, "_ordering"):
self._ordering = []
for i, form in enumerate(self.forms):
diff --git a/django/forms/models.py b/django/forms/models.py
index 574399ccb1..7fe803624e 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -70,7 +70,8 @@ def construct_instance(form, instance, fields=None, exclude=None):
if exclude and f.name in exclude:
continue
# Leave defaults for fields that aren't in POST data, except for
- # checkbox inputs because they don't appear in POST data if not checked.
+ # checkbox inputs because they don't appear in POST data if not
+ # checked.
if (
f.has_default()
and form[f.name].field.widget.value_omitted_from_data(
@@ -167,7 +168,8 @@ def fields_for_model(
``formfield_callback`` is a callable that takes a model field and returns
a form field.
- ``localized_fields`` is a list of names of fields which should be localized.
+ ``localized_fields`` is a list of names of fields which should be
+ localized.
``labels`` is a dictionary of model field names mapped to a label.
@@ -422,9 +424,9 @@ class BaseModelForm(BaseForm, AltersData):
# Exclude empty fields that are not required by the form, if the
# underlying model field is required. This keeps the model field
# from raising a required error. Note: don't exclude the field from
- # validation if the model field allows blanks. If it does, the blank
- # value may be included in a unique check, so cannot be excluded
- # from validation.
+ # validation if the model field allows blanks. If it does, the
+ # blank value may be included in a unique check, so cannot be
+ # excluded from validation.
else:
form_field = self.fields[field]
field_value = self.cleaned_data.get(field)
@@ -612,7 +614,8 @@ def modelform_factory(
``widgets`` is a dictionary of model field names mapped to a widget.
- ``localized_fields`` is a list of names of fields which should be localized.
+ ``localized_fields`` is a list of names of fields which should be
+ localized.
``formfield_callback`` is a callable that takes a model field and returns
a form field.
@@ -860,7 +863,8 @@ class BaseModelFormSet(BaseFormSet, AltersData):
for d in row_data
)
if row_data and None not in row_data:
- # if we've already seen it then we have a uniqueness failure
+ # if we've already seen it then we have a uniqueness
+ # failure
if row_data in seen_data:
# poke error messages into the right places and mark
# the form as invalid
@@ -887,7 +891,8 @@ class BaseModelFormSet(BaseFormSet, AltersData):
and form.cleaned_data[field] is not None
and form.cleaned_data[unique_for] is not None
):
- # if it's a date lookup we need to get the data for all the fields
+ # if it's a date lookup we need to get the data for all the
+ # fields
if lookup == "date":
date = form.cleaned_data[unique_for]
date_data = (date.year, date.month, date.day)
@@ -896,7 +901,8 @@ class BaseModelFormSet(BaseFormSet, AltersData):
else:
date_data = (getattr(form.cleaned_data[unique_for], lookup),)
data = (form.cleaned_data[field], *date_data)
- # if we've already seen it then we have a uniqueness failure
+ # if we've already seen it then we have a uniqueness
+ # failure
if data in seen_data:
# poke error messages into the right places and mark
# the form as invalid
@@ -1181,7 +1187,8 @@ class BaseInlineFormSet(BaseModelFormSet):
kwargs = {"pk_field": True}
else:
# The foreign key field might not be on the form, so we poke at the
- # Model field to get the label, since we need that for error messages.
+ # Model field to get the label, since we need that for error
+ # messages.
name = self.fk.name
kwargs = {
"label": getattr(
@@ -1553,12 +1560,12 @@ class ModelChoiceField(ChoiceField):
return self._choices
# Otherwise, execute the QuerySet in self.queryset to determine the
- # choices dynamically. Return a fresh ModelChoiceIterator that has not been
- # consumed. Note that we're instantiating a new ModelChoiceIterator *each*
- # time _get_choices() is called (and, thus, each time self.choices is
- # accessed) so that we can ensure the QuerySet has not been consumed. This
- # construct might look complicated but it allows for lazy evaluation of
- # the queryset.
+ # choices dynamically. Return a fresh ModelChoiceIterator that has not
+ # been consumed. Note that we're instantiating a new
+ # ModelChoiceIterator *each* time _get_choices() is called (and, thus,
+ # each time self.choices is accessed) so that we can ensure the
+ # QuerySet has not been consumed. This construct might look complicated
+ # but it allows for lazy evaluation of the queryset.
return self.iterator(self)
choices = property(_get_choices, ChoiceField.choices.fset)
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 9b5ad1b2b9..5a25b66e9a 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -71,7 +71,8 @@ class MediaAsset:
self.attributes = attributes
def __eq__(self, other):
- # Compare the path only, to ensure performant comparison in Media.merge.
+ # Compare the path only, to ensure performant comparison in
+ # Media.merge.
return (self.__class__ is other.__class__ and self.path == other.path) or (
isinstance(other, str) and self._path == other
)
@@ -161,8 +162,8 @@ class Media:
]
def render_css(self):
- # To keep rendering order consistent, we can't just iterate over items().
- # We need to sort the keys, and iterate over the sorted list.
+ # To keep rendering order consistent, we can't just iterate over
+ # items(). We need to sort the keys, and iterate over the sorted list.
media = sorted(self._css)
return chain.from_iterable(
[
@@ -585,7 +586,8 @@ class ClearableFileInput(FileInput):
# checks the "clear" checkbox), we return a unique marker
# object that FileField will turn into a ValidationError.
return FILE_INPUT_CONTRADICTION
- # False signals to clear any existing value, as opposed to just None
+ # False signals to clear any existing value, as opposed to just
+ # None
return False
return upload