Ticket #35532: form.patch

File form.patch, 2.3 KB (added by Christophe Henry, 5 months ago)
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 8084e16c8d..b4d29c3886 100644
    a b class BaseModelFormSet(BaseFormSet, AltersData):  
    847847                        # poke error messages into the right places and mark
    848848                        # the form as invalid
    849849                        errors.append(self.get_unique_error_message(unique_check))
    850                         form._errors[NON_FIELD_ERRORS] = self.error_class(
    851                             [self.get_form_error()],
    852                             renderer=self.renderer,
    853                         )
     850                        self.process_unique_error(form, unique_check, row_data)
    854851                        # Remove the data from the cleaned_data dict since it
    855852                        # was invalid.
    856853                        for field in unique_check:
    class BaseModelFormSet(BaseFormSet, AltersData):  
    883880                        # poke error messages into the right places and mark
    884881                        # the form as invalid
    885882                        errors.append(self.get_date_error_message(date_check))
    886                         form._errors[NON_FIELD_ERRORS] = self.error_class(
    887                             [self.get_form_error()],
    888                             renderer=self.renderer,
    889                         )
     883                        self.process_date_error(form, date_check, data)
    890884                        # Remove the data from the cleaned_data dict since it
    891885                        # was invalid.
    892886                        del form.cleaned_data[field]
    class BaseModelFormSet(BaseFormSet, AltersData):  
    896890        if errors:
    897891            raise ValidationError(errors)
    898892
     893    def process_unique_error(self, form, unique_check, row_data):
     894        form._errors[NON_FIELD_ERRORS] = self.error_class(
     895            [self.get_form_error()],
     896            renderer=self.renderer,
     897        )
     898
     899    def process_date_error(self, form, date_check, data):
     900        form._errors[NON_FIELD_ERRORS] = self.error_class(
     901            [self.get_form_error()],
     902            renderer=self.renderer,
     903        )
     904
    899905    def get_unique_error_message(self, unique_check):
    900906        if len(unique_check) == 1:
    901907            return gettext("Please correct the duplicate data for %(field)s.") % {
Back to Top