File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -252,7 +252,7 @@ def full_clean(self):
252
252
try :
253
253
self .clean ()
254
254
except ValidationError , e :
255
- self ._non_form_errors = e .messages
255
+ self ._non_form_errors = self . error_class ( e .messages )
256
256
257
257
def clean (self ):
258
258
"""
Original file line number Diff line number Diff line change 10
10
from django .contrib .admin .sites import LOGIN_FORM_KEY
11
11
from django .contrib .admin .util import quote
12
12
from django .contrib .admin .helpers import ACTION_CHECKBOX_NAME
13
+ from django .forms .util import ErrorList
13
14
from django .utils .cache import get_max_age
14
15
from django .utils .html import escape
15
16
@@ -966,6 +967,22 @@ def test_non_form_errors(self):
966
967
response = self .client .post ('/test_admin/admin/admin_views/person/' , data )
967
968
self .assertContains (response , "Grace is not a Zombie" )
968
969
970
+ def test_non_form_errors_is_errorlist (self ):
971
+ # test if non-form errors are correctly handled; ticket #12878
972
+ data = {
973
+ "form-TOTAL_FORMS" : "1" ,
974
+ "form-INITIAL_FORMS" : "1" ,
975
+ "form-MAX_NUM_FORMS" : "0" ,
976
+
977
+ "form-0-id" : "2" ,
978
+ "form-0-alive" : "1" ,
979
+ "form-0-gender" : "2" ,
980
+ }
981
+ response = self .client .post ('/test_admin/admin/admin_views/person/' , data )
982
+ non_form_errors = response .context ['cl' ].formset .non_form_errors ()
983
+ self .assert_ (isinstance (non_form_errors , ErrorList ))
984
+ self .assertEqual (str (non_form_errors ), str (ErrorList (["Grace is not a Zombie" ])))
985
+
969
986
def test_list_editable_ordering (self ):
970
987
collector = Collector .objects .create (id = 1 , name = "Frederick Clegg" )
971
988
Original file line number Diff line number Diff line change 598
598
>>> formset.management_form.prefix
599
599
'form'
600
600
601
+ # Regression test for #12878 #################################################
602
+
603
+ >>> data = {
604
+ ... 'drinks-TOTAL_FORMS': '2', # the number of forms rendered
605
+ ... 'drinks-INITIAL_FORMS': '0', # the number of forms with initial data
606
+ ... 'drinks-MAX_NUM_FORMS': '0', # max number of forms
607
+ ... 'drinks-0-name': 'Gin and Tonic',
608
+ ... 'drinks-1-name': 'Gin and Tonic',
609
+ ... }
610
+
611
+ >>> formset = FavoriteDrinksFormSet(data, prefix='drinks')
612
+ >>> formset.is_valid()
613
+ False
614
+ >>> print formset.non_form_errors()
615
+ <ul class="errorlist"><li>You may only specify a drink once.</li></ul>
616
+
601
617
"""
You can’t perform that action at this time.
0 commit comments