Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7878 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4772550a3cfac7792903dc0e4ed2629199a260c4 1 parent b46dc92
Brian Rosner authored July 10, 2008
14  django/contrib/admin/options.py
@@ -539,6 +539,7 @@ def add_view(self, request, form_url='', extra_context=None):
539 539
             'show_delete': False,
540 540
             'media': mark_safe(media),
541 541
             'inline_admin_formsets': inline_admin_formsets,
  542
+            'errors': AdminErrorList(form, inline_formsets),
542 543
             'root_path': self.admin_site.root_path,
543 544
         }
544 545
         context.update(extra_context or {})
@@ -616,6 +617,7 @@ def change_view(self, request, object_id, extra_context=None):
616 617
             'is_popup': request.REQUEST.has_key('_popup'),
617 618
             'media': mark_safe(media),
618 619
             'inline_admin_formsets': inline_admin_formsets,
  620
+            'errors': AdminErrorList(form, inline_formsets),
619 621
             'root_path': self.admin_site.root_path,
620 622
         }
621 623
         context.update(extra_context or {})
@@ -824,3 +826,15 @@ def deletion_field(self):
824 826
     def ordering_field(self):
825 827
         from django.newforms.formsets import ORDERING_FIELD_NAME
826 828
         return AdminField(self.form, ORDERING_FIELD_NAME, False)
  829
+
  830
+class 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())
4  django/contrib/admin/templates/admin/change_form.html
@@ -32,9 +32,9 @@
32 32
 <div>
33 33
 {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
34 34
 {% if save_on_top %}{% submit_row %}{% endif %}
35  
-{% if adminform.form.errors %}
  35
+{% if errors %}
36 36
     <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 %}
38 38
     </p>
39 39
     <ul class="errorlist">{% for error in adminform.form.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
40 40
 {% endif %}

0 notes on commit 4772550

Please sign in to comment.
Something went wrong with that request. Please try again.