Ticket #7899: formset.diff

File formset.diff, 3.9 KB (added by Peter of the Norse <RahmCoff@…>, 16 years ago)

little diff

  • django/newforms/formsets.py

     
    4747            if self.management_form.is_valid():
    4848                self._total_form_count = self.management_form.cleaned_data[TOTAL_FORM_COUNT]
    4949                self._initial_form_count = self.management_form.cleaned_data[INITIAL_FORM_COUNT]
    50                 self._max_form_count = self.management_form.cleaned_data[MAX_FORM_COUNT]
     50                self.max_form_count = self.management_form.cleaned_data[MAX_FORM_COUNT]
    5151            else:
    5252                raise ValidationError('ManagementForm data is missing or has been tampered with')
    5353        else:
    5454            if initial:
    5555                self._initial_form_count = len(initial)
    56                 if self._initial_form_count > self._max_form_count and self._max_form_count > 0:
    57                     self._initial_form_count = self._max_form_count
     56                if self._initial_form_count > self.max_form_count and self.max_form_count > 0:
     57                    self._initial_form_count = self.max_form_count
    5858                self._total_form_count = self._initial_form_count + self.extra
    5959            else:
    6060                self._initial_form_count = 0
    6161                self._total_form_count = self.extra
    62             if self._total_form_count > self._max_form_count and self._max_form_count > 0:
    63                 self._total_form_count = self._max_form_count
     62            if self._total_form_count > self.max_form_count and self.max_form_count > 0:
     63                self._total_form_count = self.max_form_count
    6464            initial = {TOTAL_FORM_COUNT: self._total_form_count,
    6565                       INITIAL_FORM_COUNT: self._initial_form_count,
    66                        MAX_FORM_COUNT: self._max_form_count}
     66                       MAX_FORM_COUNT: self.max_form_count}
    6767            self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix)
    6868       
    6969        # construct the forms in the formset
     
    280280    """Return a FormSet for the given form class."""
    281281    attrs = {'form': form, 'extra': extra,
    282282             'can_order': can_order, 'can_delete': can_delete,
    283              '_max_form_count': max_num}
     283             'max_form_count': max_num}
    284284    return type(form.__name__ + 'FormSet', (formset,), attrs)
    285285
    286286def all_valid(formsets):
  • django/newforms/models.py

     
    306306                 queryset=None, **kwargs):
    307307        self.queryset = queryset
    308308        defaults = {'data': data, 'files': files, 'auto_id': auto_id, 'prefix': prefix}
    309         if self._max_form_count > 0:
    310             qs = self.get_queryset()[:self._max_form_count]
     309        if self.max_form_count > 0:
     310            qs = self.get_queryset()[:self.max_form_count]
    311311        else:
    312312            qs = self.get_queryset()
    313313        defaults['initial'] = [model_to_dict(obj) for obj in qs]
     
    402402
    403403class BaseInlineFormset(BaseModelFormSet):
    404404    """A formset for child objects related to a parent."""
    405     def __init__(self, data=None, files=None, instance=None, save_as_new=False):
     405    def __init__(self, data=None, files=None, instance=None, save_as_new=False, prefix=None):
    406406        from django.db.models.fields.related import RelatedObject
    407407        self.instance = instance
    408408        self.save_as_new = save_as_new
    409409        # is there a better way to get the object descriptor?
    410410        self.rel_name = RelatedObject(self.fk.rel.to, self.model, self.fk).get_accessor_name()
    411         super(BaseInlineFormset, self).__init__(data, files, prefix=self.rel_name)
     411        super(BaseInlineFormset, self).__init__(data, files, prefix=(prefix or self.rel_name))
    412412   
    413413    def _construct_forms(self):
    414414        if self.save_as_new:
Back to Top