Author: brosner
Date: 2008-07-10 15:24:46 -0500 (Thu, 10 Jul 2008)
New Revision: 7878
Modified:
django/branches/newforms-admin/django/contrib/admin/options.py
django/branches/newforms-admin/django/contrib/admin/templates/admin/change_form.html
Log:
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.
Modified: django/branches/newforms-admin/django/contrib/admin/options.py
===================================================================
--- django/branches/newforms-admin/django/contrib/admin/options.py
2008-07-10 13:53:45 UTC (rev 7877)
+++ django/branches/newforms-admin/django/contrib/admin/options.py
2008-07-10 20:24:46 UTC (rev 7878)
@@ -539,6 +539,7 @@
'show_delete': False,
'media': mark_safe(media),
'inline_admin_formsets': inline_admin_formsets,
+ 'errors': AdminErrorList(form, inline_formsets),
'root_path': self.admin_site.root_path,
}
context.update(extra_context or {})
@@ -616,6 +617,7 @@
'is_popup': request.REQUEST.has_key('_popup'),
'media': mark_safe(media),
'inline_admin_formsets': inline_admin_formsets,
+ 'errors': AdminErrorList(form, inline_formsets),
'root_path': self.admin_site.root_path,
}
context.update(extra_context or {})
@@ -824,3 +826,15 @@
def ordering_field(self):
from django.newforms.formsets import ORDERING_FIELD_NAME
return AdminField(self.form, ORDERING_FIELD_NAME, False)
+
+class AdminErrorList(forms.util.ErrorList):
+ """
+ Stores all errors for the form/formsets in an add/change stage view.
+ """
+ def __init__(self, form, inline_formsets):
+ if form.is_bound:
+ self.extend(form.errors.values())
+ for inline_formset in inline_formsets:
+ self.extend(inline_formset.non_form_errors())
+ for errors_in_inline_form in inline_formset.errors:
+ self.extend(errors_in_inline_form.values())
Modified:
django/branches/newforms-admin/django/contrib/admin/templates/admin/change_form.html
===================================================================
---
django/branches/newforms-admin/django/contrib/admin/templates/admin/change_form.html
2008-07-10 13:53:45 UTC (rev 7877)
+++
django/branches/newforms-admin/django/contrib/admin/templates/admin/change_form.html
2008-07-10 20:24:46 UTC (rev 7878)
@@ -32,9 +32,9 @@
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if save_on_top %}{% submit_row %}{% endif %}
-{% if adminform.form.errors %}
+{% if errors %}
<p class="errornote">
- {% blocktrans count adminform.form.errors.items|length as counter %}Please
correct the error below.{% plural %}Please correct the errors below.{%
endblocktrans %}
+ {% blocktrans count errors.items|length as counter %}Please correct the
error below.{% plural %}Please correct the errors below.{% endblocktrans %}
</p>
<ul class="errorlist">{% for error in adminform.form.non_field_errors
%}<li>{{ error }}</li>{% endfor %}</ul>
{% endif %}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---