Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #18751 -- Cleaned up BaseFormSet._should_delete_form

We can do that now that cleaned_data is guaranteed to be
present. Related to [121fd10].
Thanks Simon Charette for his work on the ticket.
  • Loading branch information...
commit fb3d916c201d5882098bbcc94f60765412ba7aff 1 parent ae88e73
@claudep claudep authored
Showing with 9 additions and 8 deletions.
  1. +4 −7 django/forms/formsets.py
  2. +5 −1 django/forms/models.py
View
11 django/forms/formsets.py
@@ -254,13 +254,10 @@ def _get_errors(self):
errors = property(_get_errors)
def _should_delete_form(self, form):
- # The way we lookup the value of the deletion field here takes
- # more code than we'd like, but the form's cleaned_data will
- # not exist if the form is invalid.
- field = form.fields[DELETION_FIELD_NAME]
- raw_value = form._raw_value(DELETION_FIELD_NAME)
- should_delete = field.clean(raw_value)
- return should_delete
+ """
+ Returns whether or not the form was marked for deletion.
+ """
+ return form.cleaned_data.get(DELETION_FIELD_NAME, False)
def is_valid(self):
"""
View
6 django/forms/models.py
@@ -591,6 +591,10 @@ def save_existing_objects(self, commit=True):
return []
saved_instances = []
+ try:
+ forms_to_delete = self.deleted_forms
+ except AttributeError:
+ forms_to_delete = []
for form in self.initial_forms:
pk_name = self._pk_field.name
raw_pk_value = form._raw_value(pk_name)
@@ -601,7 +605,7 @@ def save_existing_objects(self, commit=True):
pk_value = getattr(pk_value, 'pk', pk_value)
obj = self._existing_object(pk_value)
- if self.can_delete and self._should_delete_form(form):
+ if form in forms_to_delete:
self.deleted_objects.append(obj)
obj.delete()
continue
Please sign in to comment.
Something went wrong with that request. Please try again.