Ticket #33622: patch.diff

File patch.diff, 2.5 KB (added by Christoph Schindler, 3 years ago)
  • django/forms/formsets.py

    diff --git a/django/forms/formsets.py b/django/forms/formsets.py
    index a89c35599f..39cd47866a 100644
    a b from django.forms.widgets import HiddenInput, NumberInput  
    66from django.utils.functional import cached_property
    77from django.utils.html import html_safe
    88from django.utils.safestring import mark_safe
    9 from django.utils.translation import gettext_lazy as _, ngettext
     9from django.utils.translation import gettext_lazy as _, ngettext_lazy
    1010
    1111__all__ = ('BaseFormSet', 'formset_factory', 'all_valid')
    1212
    class BaseFormSet:  
    6161            'ManagementForm data is missing or has been tampered with. Missing fields: '
    6262            '%(field_names)s. You may need to file a bug report if the issue persists.'
    6363        ),
     64        'too_many_forms': ngettext_lazy(
     65            "Please submit at most {num} form.",
     66            "Please submit at most {num} forms.",
     67            'num'
     68        ),
     69        'too_few_forms': ngettext_lazy(
     70            "Please submit at least {num} form.",
     71            "Please submit at least {num} forms.",
     72            'num'
     73        ),
    6474    }
    6575
    6676    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
    class BaseFormSet:  
    366376            if (self.validate_max and
    367377                    self.total_form_count() - len(self.deleted_forms) > self.max_num) or \
    368378                    self.management_form.cleaned_data[TOTAL_FORM_COUNT] > self.absolute_max:
    369                 raise ValidationError(ngettext(
    370                     "Please submit at most %d form.",
    371                     "Please submit at most %d forms.", self.max_num) % self.max_num,
     379                raise ValidationError(
     380                    self.error_messages['too_many_forms'].format(num=self.max_num),
    372381                    code='too_many_forms',
    373382                )
    374383            if (self.validate_min and
    375384                    self.total_form_count() - len(self.deleted_forms) - empty_forms_count < self.min_num):
    376                 raise ValidationError(ngettext(
    377                     "Please submit at least %d form.",
    378                     "Please submit at least %d forms.", self.min_num) % self.min_num,
    379                     code='too_few_forms')
     385                raise ValidationError(
     386                    self.error_messages['too_few_forms'].format(num=self.min_num),
     387                    code='too_few_forms',
     388                )
    380389            # Give self.clean() a chance to do cross-form validation.
    381390            self.clean()
    382391        except ValidationError as e:
Back to Top