Django

Code

Changeset 7878

Show
Ignore:
Timestamp:
07/10/08 15:24:46 (5 months ago)
Author:
brosner
Message:

newforms-admin: Fixed #5628 -- When inlines have validation errors an error message is now displayed at the top of the page. Thanks Petr Marhoun for the improved patch.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin/django/contrib/admin/options.py

    r7875 r7878  
    540540            'media': mark_safe(media), 
    541541            'inline_admin_formsets': inline_admin_formsets, 
     542            'errors': AdminErrorList(form, inline_formsets), 
    542543            'root_path': self.admin_site.root_path, 
    543544        } 
     
    617618            'media': mark_safe(media), 
    618619            'inline_admin_formsets': inline_admin_formsets, 
     620            'errors': AdminErrorList(form, inline_formsets), 
    619621            'root_path': self.admin_site.root_path, 
    620622        } 
     
    825827        from django.newforms.formsets import ORDERING_FIELD_NAME 
    826828        return AdminField(self.form, ORDERING_FIELD_NAME, False) 
     829 
     830class AdminErrorList(forms.util.ErrorList): 
     831    """ 
     832    Stores all errors for the form/formsets in an add/change stage view. 
     833    """ 
     834    def __init__(self, form, inline_formsets): 
     835        if form.is_bound: 
     836            self.extend(form.errors.values()) 
     837            for inline_formset in inline_formsets: 
     838                self.extend(inline_formset.non_form_errors()) 
     839                for errors_in_inline_form in inline_formset.errors: 
     840                    self.extend(errors_in_inline_form.values()) 
  • django/branches/newforms-admin/django/contrib/admin/templates/admin/change_form.html

    r7638 r7878  
    3333{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %} 
    3434{% if save_on_top %}{% submit_row %}{% endif %} 
    35 {% if adminform.form.errors %} 
     35{% if errors %} 
    3636    <p class="errornote"> 
    37     {% blocktrans count adminform.form.errors.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} 
     37    {% blocktrans count errors.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} 
    3838    </p> 
    3939    <ul class="errorlist">{% for error in adminform.form.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>