Ticket #9749: 9749-different-approach.diff
File 9749-different-approach.diff, 4.5 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/options.py
885 885 context.update(extra_context or {}) 886 886 return self.render_change_form(request, context, change=True, obj=obj) 887 887 888 def get_changelist(self, request, **kwargs): 889 from django.contrib.admin.views.main import ChangeList 890 return ChangeList 891 888 892 @csrf_protect 889 893 def changelist_view(self, request, extra_context=None): 890 894 "The 'change list' admin view for this model." 891 from django.contrib.admin.views.main import ChangeList,ERROR_FLAG895 from django.contrib.admin.views.main import ERROR_FLAG 892 896 opts = self.model._meta 893 897 app_label = opts.app_label 894 898 if not self.has_change_permission(request, None): … … 905 909 except ValueError: 906 910 pass 907 911 912 changelist = self.get_changelist(request) 908 913 try: 909 cl = ChangeList(request, self.model, list_display, self.list_display_links, self.list_filter,914 cl = changelist(request, self.model, list_display, self.list_display_links, self.list_filter, 910 915 self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self) 911 916 except IncorrectLookupParameters: 912 917 # Wacky lookup parameters were given, so redirect to the main -
tests/regressiontests/admin_views/tests.py
1203 1203 self.failUnlessEqual(Subscriber.objects.count(), 2) 1204 1204 1205 1205 1206 class TestCustomChangeList(TestCase): 1207 fixtures = ['admin-views-users.xml'] 1208 1209 urlbit = 'admin' 1210 1211 def setUp(self): 1212 result = self.client.login(username='super', password='secret') 1213 self.failUnlessEqual(result, True) 1214 1215 def tearDown(self): 1216 self.client.logout() 1217 1218 def test_custom_changelist(self): 1219 """ 1220 Validate that a custom ChangeList class can be used (#9749) 1221 """ 1222 # Insert some data 1223 post_data = {"name": u"First Gadget"} 1224 response = self.client.post('/test_admin/%s/admin_views/gadget/add/' % self.urlbit, post_data) 1225 self.failUnlessEqual(response.status_code, 302) # redirect somewhere 1226 # Hit the page once to get messages out of the queue message list 1227 response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit) 1228 # Ensure that that data is still not visible on the page 1229 response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit) 1230 self.failUnlessEqual(response.status_code, 200) 1231 self.assertNotContains(response, 'First Gadget') 1232 1233 1206 1234 class TestInlineNotEditable(TestCase): 1207 1235 fixtures = ['admin-views-users.xml'] 1208 1236 -
tests/regressiontests/admin_views/models.py
4 4 from django.core.files.storage import FileSystemStorage 5 5 from django.db import models 6 6 from django.contrib import admin 7 from django.contrib.admin.views.main import ChangeList 7 8 from django.core.mail import EmailMessage 8 9 9 10 class Section(models.Model): … … 420 421 class CollectorAdmin(admin.ModelAdmin): 421 422 inlines = [WidgetInline, DooHickeyInline, GrommetInline, WhatsitInline, FancyDoodadInline, CategoryInline] 422 423 424 class Gadget(models.Model): 425 name = models.CharField(max_length=100) 426 427 def __unicode__(self): 428 return self.name 429 430 class CustomChangeList(ChangeList): 431 def get_query_set(self): 432 return self.root_query_set.filter(pk=9999) # Does not exist 433 434 class GadgetAdmin(admin.ModelAdmin): 435 def get_changelist(self, request, **kwargs): 436 return CustomChangeList 437 423 438 admin.site.register(Article, ArticleAdmin) 424 439 admin.site.register(CustomArticle, CustomArticleAdmin) 425 440 admin.site.register(Section, save_as=True, inlines=[ArticleInline]) … … 443 458 admin.site.register(Recommender) 444 459 admin.site.register(Collector, CollectorAdmin) 445 460 admin.site.register(Category, CategoryAdmin) 461 admin.site.register(Gadget, GadgetAdmin) 446 462 447 463 # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. 448 464 # That way we cover all four cases: