Ticket #10711: 10711-2.diff

File 10711-2.diff, 1.6 KB (added by Claude Paroz, 12 years ago)

Use cleaned_data in _should_delete_form

  • django/forms/formsets.py

    diff --git a/django/forms/formsets.py b/django/forms/formsets.py
    index 1ec8340..d652130 100644
    a b class BaseFormSet(StrAndUnicode):  
    251251    errors = property(_get_errors)
    252252
    253253    def _should_delete_form(self, form):
    254         # The way we lookup the value of the deletion field here takes
    255         # more code than we'd like, but the form's cleaned_data will
    256         # not exist if the form is invalid.
    257         field = form.fields[DELETION_FIELD_NAME]
    258         raw_value = form._raw_value(DELETION_FIELD_NAME)
    259         should_delete = field.clean(raw_value)
    260         return should_delete
     254        return form.cleaned_data.get(DELETION_FIELD_NAME, False)
    261255
    262256    def is_valid(self):
    263257        """
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index e6ae357..553f174 100644
    a b class BaseModelFormSet(BaseFormSet):  
    596596            return []
    597597
    598598        saved_instances = []
     599        try:
     600            forms_to_delete = self.deleted_forms
     601        except AttributeError:
     602            forms_to_delete = []
    599603        for form in self.initial_forms:
    600604            pk_name = self._pk_field.name
    601605            raw_pk_value = form._raw_value(pk_name)
    class BaseModelFormSet(BaseFormSet):  
    606610            pk_value = getattr(pk_value, 'pk', pk_value)
    607611
    608612            obj = self._existing_object(pk_value)
    609             if self.can_delete and self._should_delete_form(form):
     613            if form in forms_to_delete:
    610614                self.deleted_objects.append(obj)
    611615                obj.delete()
    612616                continue
Back to Top