Ticket #5628: 5628_formset_errors_fix.diff

File 5628_formset_errors_fix.diff, 3.2 KB (added by Brian Rosner, 17 years ago)
  • django/newforms/formsets.py

    === django/newforms/formsets.py
    ==================================================================
     
    8787                change_form = FormClass(**kwargs)
    8888                self.add_fields(change_form, i)
    8989                change_forms.append(change_form)
    90             self._change_forms= change_forms
     90            self._change_forms = change_forms
    9191        return self._change_forms
    9292    change_forms = property(_get_change_forms)
    9393
  • django/contrib/admin/options.py

    === django/contrib/admin/options.py
    ==================================================================
     
    521521            'is_popup': request.REQUEST.has_key('_popup'),
    522522            'show_delete': False,
    523523            'media': media,
    524             'inline_admin_formsets': inline_admin_formsets,
     524            'inline_admin_formsets': InlineAdminFormSetList(inline_admin_formsets),
    525525        })
    526526        return self.render_change_form(model, c, add=True)
    527527   
     
    596596            'original': obj,
    597597            'is_popup': request.REQUEST.has_key('_popup'),
    598598            'media': media,
    599             'inline_admin_formsets': inline_admin_formsets,
     599            'inline_admin_formsets': InlineAdminFormSetList(inline_admin_formsets),
    600600        })
    601601        return self.render_change_form(model, c, change=True)
    602602
     
    766766class TabularInline(InlineModelAdmin):
    767767    template = 'admin/edit_inline/tabular.html'
    768768
     769class InlineAdminFormSetList(object):
     770    def __init__(self, admin_formsets):
     771        self.admin_formsets = admin_formsets
     772        self.formsets = [ifs.formset for ifs in admin_formsets]
     773   
     774    def __iter__(self):
     775        return iter(self.admin_formsets)
     776   
     777    def _get_errors(self):
     778        errors = []
     779        for formset in self.formsets:
     780            # HACK: a FormSet object does not always have an errors attribute.
     781            # this will work without the hasattr check for errors since its only
     782            # usage is in the template and variable resolution will suppress the
     783            # AttributeError exception thrown.
     784            if hasattr(formset, 'errors'):
     785                errors.append(formset.errors)
     786        return bool(errors)
     787    errors = property(_get_errors)
     788
    769789class InlineAdminFormSet(object):
    770790    """
    771791    A wrapper around an inline formset for use in the admin system.
  • django/contrib/admin/templates/admin/change_form.html

    === django/contrib/admin/templates/admin/change_form.html
    ==================================================================
     
    3434<div>
    3535{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
    3636{% if save_on_top %}{% submit_row %}{% endif %}
    37 {% if adminform.form.errors %}
     37{% if adminform.form.errors or inline_admin_formsets.errors %}
    3838    <p class="errornote">
    3939    {% blocktrans count adminform.form.errors.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
    4040    </p>
Back to Top