Ticket #13126: 13126_changelist_non_field_errors.2.diff
File 13126_changelist_non_field_errors.2.diff, 6.3 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/templates/admin/change_list_results.html
diff --git a/django/contrib/admin/templates/admin/change_list_results.html b/django/contrib/admin/templates/admin/change_list_results.html index 3e38978..29cf265 100644
a b 16 16 </thead> 17 17 <tbody> 18 18 {% for result in results %} 19 <tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr> 19 {% if result.form.non_field_errors %} 20 <tr><td colspan="{{ result.row|length }}">{{ result.form.non_field_errors }}</td></tr> 21 {% endif %} 22 <tr class="{% cycle 'row1' 'row2' %}">{% for item in result.row %}{{ item }}{% endfor %}</tr> 20 23 {% endfor %} 21 24 </tbody> 22 25 </table> -
django/contrib/admin/templatetags/admin_list.py
diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index 806be24..0e8d0b5 100644
a b def items_for_result(cl, result, form): 198 198 def results(cl): 199 199 if cl.formset: 200 200 for res, form in zip(cl.result_list, cl.formset.forms): 201 yield list(items_for_result(cl, res, form))201 yield {'row': list(items_for_result(cl, res, form)), 'form': form} 202 202 else: 203 203 for res in cl.result_list: 204 yield list(items_for_result(cl, res, None))204 yield {'row': list(items_for_result(cl, res, None)), 'form': None} 205 205 206 206 def result_hidden_fields(cl): 207 207 if cl.formset: -
tests/regressiontests/admin_views/models.py
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index 60319ea..c6dd9c1 100644
a b class Answer(models.Model): 669 669 class Reservation(models.Model): 670 670 start_date = models.DateTimeField() 671 671 price = models.IntegerField() 672 673 674 DRIVER_CHOICES = ( 675 (u'bill', 'Bill G'), 676 (u'steve', 'Steve J'), 677 ) 678 679 RESTAURANT_CHOICES = ( 680 (u'indian', u'A Taste of India'), 681 (u'thai', u'Thai Pography'), 682 (u'pizza', u'Pizza Mama'), 683 ) 684 685 class FoodDelivery(models.Model): 686 reference = models.CharField(max_length=100) 687 driver = models.CharField(max_length=100, choices=DRIVER_CHOICES, blank=True) 688 restaurant = models.CharField(max_length=100, choices=RESTAURANT_CHOICES, blank=True) 689 690 class Meta: 691 unique_together = (("driver", "restaurant"),) 672 692 673 693 admin.site.register(Article, ArticleAdmin) 674 694 admin.site.register(CustomArticle, CustomArticleAdmin) … … admin.site.register(CyclicOne) 706 726 admin.site.register(CyclicTwo) 707 727 admin.site.register(WorkHour, WorkHourAdmin) 708 728 admin.site.register(Reservation) 729 admin.site.register(FoodDelivery, list_display=('reference', 'driver', 'restaurant'), list_editable = ('driver', 'restaurant')) 709 730 710 731 # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. 711 732 # That way we cover all four cases: -
tests/regressiontests/admin_views/tests.py
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index acbbbfc..a30a319 100644
a b from models import (Article, BarAccount, CustomArticle, EmptyModel, 35 35 Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, 36 36 Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, 37 37 Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee, 38 Question, Answer, Inquisition, Actor )38 Question, Answer, Inquisition, Actor, FoodDelivery) 39 39 40 40 41 41 class AdminViewBasicTest(TestCase): … … class AdminViewListEditable(TestCase): 1420 1420 1421 1421 self.assertEqual(Person.objects.get(name="John Mauchly").alive, False) 1422 1422 1423 def test_non_field_errors(self): 1424 ''' Ensure that non field errors are displayed for each of the 1425 forms in the changelist's formset. Refs #13126. 1426 ''' 1427 FoodDelivery.objects.create(reference='123', driver='bill', restaurant='thai') 1428 FoodDelivery.objects.create(reference='456', driver='bill', restaurant='india') 1429 FoodDelivery.objects.create(reference='789', driver='bill', restaurant='pizza') 1430 1431 data = { 1432 "form-TOTAL_FORMS": "3", 1433 "form-INITIAL_FORMS": "3", 1434 "form-MAX_NUM_FORMS": "0", 1435 1436 "form-0-id": "1", 1437 "form-0-reference": "123", 1438 "form-0-driver": "bill", 1439 "form-0-restaurant": "thai", 1440 1441 # Same data as above: Forbidden because of unique_together! 1442 "form-1-id": "2", 1443 "form-1-reference": "456", 1444 "form-1-driver": "bill", 1445 "form-1-restaurant": "thai", 1446 1447 "form-2-id": "3", 1448 "form-2-reference": "789", 1449 "form-2-driver": "bill", 1450 "form-2-restaurant": "pizza", 1451 1452 "_save": "Save", 1453 } 1454 response = self.client.post('/test_admin/admin/admin_views/fooddelivery/', data) 1455 self.assertContains(response, '<tr><td colspan="4"><ul class="errorlist"><li>Food delivery with this Driver and Restaurant already exists.</li></ul></td></tr>', 1) 1456 1457 data = { 1458 "form-TOTAL_FORMS": "3", 1459 "form-INITIAL_FORMS": "3", 1460 "form-MAX_NUM_FORMS": "0", 1461 1462 "form-0-id": "1", 1463 "form-0-reference": "123", 1464 "form-0-driver": "bill", 1465 "form-0-restaurant": "thai", 1466 1467 # Same data as above: Forbidden because of unique_together! 1468 "form-1-id": "2", 1469 "form-1-reference": "456", 1470 "form-1-driver": "bill", 1471 "form-1-restaurant": "thai", 1472 1473 # Same data also. 1474 "form-2-id": "3", 1475 "form-2-reference": "789", 1476 "form-2-driver": "bill", 1477 "form-2-restaurant": "thai", 1478 1479 "_save": "Save", 1480 } 1481 response = self.client.post('/test_admin/admin/admin_views/fooddelivery/', data) 1482 self.assertContains(response, '<tr><td colspan="4"><ul class="errorlist"><li>Food delivery with this Driver and Restaurant already exists.</li></ul></td></tr>', 2) 1483 1423 1484 def test_non_form_errors(self): 1424 1485 # test if non-form errors are handled; ticket #12716 1425 1486 data = {