Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #12716 - Typo in the admin change list template. Thanks…

…, kbrownlees.

Backport of r12398 and r12448.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12453 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 77192eb661ffc1768d75cb3ed4f253240da8e6c0 1 parent df1ad56
Jannis Leidel authored February 16, 2010
2  django/contrib/admin/templates/admin/change_list.html
@@ -54,7 +54,7 @@
54 54
         <p class="errornote">
55 55
         {% blocktrans count cl.formset.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
56 56
         </p>
57  
-        <ul class="errorlist">{% for error in cl.formset.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
  57
+        <ul class="errorlist">{% for error in cl.formset.non_form_errors %}<li>{{ error }}</li>{% endfor %}</ul>
58 58
     {% endif %}
59 59
     <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
60 60
       {% block search %}{% search_form cl %}{% endblock %}
14  tests/regressiontests/admin_views/models.py
@@ -5,6 +5,8 @@
5 5
 from django.db import models
6 6
 from django.contrib import admin
7 7
 from django.core.mail import EmailMessage
  8
+from django import forms
  9
+from django.forms.models import BaseModelFormSet
8 10
 
9 11
 class Section(models.Model):
10 12
     """
@@ -168,6 +170,14 @@ def __unicode__(self):
168 170
     class Meta:
169 171
         ordering = ["id"]
170 172
 
  173
+class BasePersonModelFormSet(BaseModelFormSet):
  174
+    def clean(self):
  175
+        for person_dict in self.cleaned_data:
  176
+            person = person_dict.get('id')
  177
+            alive = person_dict.get('alive')
  178
+            if person and alive and person.name == "Grace Hopper":
  179
+                raise forms.ValidationError, "Grace is not a Zombie"
  180
+
171 181
 class PersonAdmin(admin.ModelAdmin):
172 182
     list_display = ('name', 'gender', 'alive')
173 183
     list_editable = ('gender', 'alive')
@@ -176,6 +186,10 @@ class PersonAdmin(admin.ModelAdmin):
176 186
     ordering = ["id"]
177 187
     save_as = True
178 188
 
  189
+    def get_changelist_formset(self, request, **kwargs):
  190
+        return super(PersonAdmin, self).get_changelist_formset(request,
  191
+            formset=BasePersonModelFormSet, **kwargs)
  192
+
179 193
 class Persona(models.Model):
180 194
     """
181 195
     A simple persona associated with accounts, to test inlining of related
14  tests/regressiontests/admin_views/tests.py
@@ -921,7 +921,6 @@ def test_post_submission(self):
921 921
             "form-2-id": "3",
922 922
         }
923 923
         self.client.post('/test_admin/admin/admin_views/person/', data)
924  
-
925 924
         self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
926 925
         self.failUnlessEqual(Person.objects.get(name="Grace Hopper").gender, 2)
927 926
 
@@ -954,6 +953,19 @@ def test_post_submission(self):
954 953
 
955 954
         self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
956 955
 
  956
+    def test_non_form_errors(self):
  957
+        # test if non-form errors are handled; ticket #12716
  958
+        data = {
  959
+            "form-TOTAL_FORMS": "1",
  960
+            "form-INITIAL_FORMS": "1",
  961
+
  962
+            "form-0-id": "2",
  963
+            "form-0-alive": "1",
  964
+            "form-0-gender": "2",
  965
+        }
  966
+        response = self.client.post('/test_admin/admin/admin_views/person/', data)
  967
+        self.assertContains(response, "Grace is not a Zombie")
  968
+
957 969
     def test_list_editable_ordering(self):
958 970
         collector = Collector.objects.create(id=1, name="Frederick Clegg")
959 971
 

0 notes on commit 77192eb

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