Ticket #12475: 12475_changelist_hidden_fields.diff
File 12475_changelist_hidden_fields.diff, 5.0 KB (added by , 14 years ago) |
---|
-
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..133e0fc 100644
a b def items_for_result(cl, result, form): 186 186 # By default the fields come from ModelAdmin.list_editable, but if we pull 187 187 # the fields out of the form instead of list_editable custom admins 188 188 # can provide fields on a per request basis 189 if form and field_name in form.fields :189 if form and field_name in form.fields and not form[field_name].is_hidden: 190 190 bf = form[field_name] 191 191 result_repr = mark_safe(force_unicode(bf.errors) + force_unicode(bf)) 192 192 else: -
tests/regressiontests/admin_views/models.py
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index 60319ea..1890674 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 class Story(models.Model): 674 title = models.CharField(max_length=100) 675 content = models.TextField() 676 677 class StoryAdmin(admin.ModelAdmin): 678 list_display = ('id', 'title', 'content') 679 list_display_links = ('title',) # 'id' not in list_display_links 680 list_editable = ('content', ) 681 682 class OtherStory(models.Model): 683 title = models.CharField(max_length=100) 684 content = models.TextField() 685 686 class OtherStoryAdmin(admin.ModelAdmin): 687 list_display = ('id', 'title', 'content') 688 list_display_links = ('title', 'id') # 'id' in list_display_links 689 list_editable = ('content', ) 672 690 673 691 admin.site.register(Article, ArticleAdmin) 674 692 admin.site.register(CustomArticle, CustomArticleAdmin) … … admin.site.register(CyclicOne) 706 724 admin.site.register(CyclicTwo) 707 725 admin.site.register(WorkHour, WorkHourAdmin) 708 726 admin.site.register(Reservation) 727 admin.site.register(Story, StoryAdmin) 728 admin.site.register(OtherStory, OtherStoryAdmin) 709 729 710 730 # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. 711 731 # 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..b3c691a 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, Story, OtherStory) 39 39 40 40 41 41 class AdminViewBasicTest(TestCase): … … class AdminViewListEditable(TestCase): 1563 1563 response = self.client.get('/test_admin/admin/admin_views/person/?%s' % IS_POPUP_VAR) 1564 1564 self.assertEqual(response.context['cl'].list_editable, ()) 1565 1565 1566 1566 def test_hidden_fields(self): 1567 """ Ensure that hidden fields aren't displayed in the table body and 1568 that their corresponding human-readable value is displayed instead. 1569 Note that hidden fields should in fact be displayed but separately 1570 (not in the table) and only once. 1571 Refs #12475. 1572 """ 1573 Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...') 1574 Story.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...') 1575 response = self.client.get('/test_admin/admin/admin_views/story/') 1576 self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table. 1577 self.assertContains(response, 'id="id_form-1-id"', 1) 1578 self.assertContains(response, '<td>1</td>', 1) 1579 self.assertContains(response, '<td>2</td>', 1) 1580 1581 def test_hidden_fields_with_list_display_links(self): 1582 """ Similarly as test_hidden_fields, but when the hidden fields are 1583 referenced in list_display_links. 1584 Refs #12475. 1585 """ 1586 OtherStory.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...') 1587 OtherStory.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...') 1588 response = self.client.get('/test_admin/admin/admin_views/otherstory/') 1589 self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table. 1590 self.assertContains(response, 'id="id_form-1-id"', 1) 1591 self.assertContains(response, '<th><a href="1/">1</a></th>', 1) 1592 self.assertContains(response, '<th><a href="2/">2</a></th>', 1) 1593 1567 1594 class AdminSearchTest(TestCase): 1568 1595 fixtures = ['admin-views-users','multiple-child-classes'] 1569 1596