Ticket #9749: patch_django_9749.20090507.diff
File patch_django_9749.20090507.diff, 7.0 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/validation.py
8 8 from django.forms.models import BaseModelForm, BaseModelFormSet, fields_for_model, _get_foreign_key 9 9 from django.contrib.admin.options import flatten_fieldsets, BaseModelAdmin 10 10 from django.contrib.admin.options import HORIZONTAL, VERTICAL 11 from django.contrib.admin.views.main import ChangeList 11 12 12 13 __all__ = ['validate'] 13 14 … … 148 149 validate_base(inline, inline.model) 149 150 validate_inline(inline, cls, model) 150 151 152 # changelist_class = ChangeList 153 if hasattr(cls, 'changelist_class') and not issubclass(cls.changelist_class, ChangeList): 154 raise ImproperlyConfigured("'%s.changelist_class' does not inherit " 155 "from admin.views.main.ChangeList." % cls.__name__) 156 151 157 def validate_inline(cls, parent, parent_model): 152 158 # model is already verified to exist and be a Model 153 159 if cls.fk_name: # default value is None -
django/contrib/admin/options.py
174 174 175 175 class ModelAdmin(BaseModelAdmin): 176 176 "Encapsulates all admin options and functionality for a given model." 177 # Avoid circular import of ChangeList 178 from django.contrib.admin.views.main import ChangeList 179 177 180 __metaclass__ = forms.MediaDefiningClass 178 181 179 182 list_display = ('__str__',) … … 188 191 save_on_top = False 189 192 ordering = None 190 193 inlines = [] 191 194 changelist_class = ChangeList 195 192 196 # Custom templates (designed to be over-ridden in subclasses) 193 197 change_form_template = None 194 198 change_list_template = None … … 874 878 875 879 def changelist_view(self, request, extra_context=None): 876 880 "The 'change list' admin view for this model." 877 from django.contrib.admin.views.main import ChangeList, ERROR_FLAG878 881 opts = self.model._meta 879 882 app_label = opts.app_label 880 883 if not self.has_change_permission(request, None): … … 892 895 pass 893 896 894 897 try: 895 cl = ChangeList(request, self.model, list_display, self.list_display_links, self.list_filter,898 cl = self.changelist_class(request, self.model, list_display, self.list_display_links, self.list_filter, 896 899 self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self) 897 900 except IncorrectLookupParameters: 898 901 # Wacky lookup parameters were given, so redirect to the main … … 900 903 # parameter via the query string. If wacky parameters were given and 901 904 # the 'invalid=1' parameter was already in the query string, something 902 905 # is screwed up with the database, so display an error page. 906 from django.contrib.admin.views.main import ERROR_FLAG 903 907 if ERROR_FLAG in request.GET.keys(): 904 908 return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) 905 909 return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1') -
tests/regressiontests/admin_views/tests.py
1050 1050 self.assertEquals(len(mail.outbox), 1) 1051 1051 self.assertEquals(mail.outbox[0].subject, 'Greetings from a function action') 1052 1052 1053 1054 class AdminCustomChangeListTest(TestCase): 1055 fixtures = ['admin-views-users.xml'] 1056 1057 def setUp(self): 1058 self.client.login(username='super', password='secret') 1059 1060 def tearDown(self): 1061 self.client.logout() 1062 1063 def testCustomLinkPresence(self): 1064 """ 1065 A test to ensure that custom ChangeList class works as expected. 1066 """ 1067 post_data = { 1068 "title": u"Lion", 1069 } 1070 response = self.client.post('/test_admin/admin/admin_views/animal/add/', post_data) 1071 self.failUnlessEqual(response.status_code, 302) # redirect somewhere 1072 response = self.client.get('/test_admin/admin/admin_views/animal/') 1073 self.failUnlessEqual(response.status_code, 200) 1074 should_contain = """<a href="custom/1/">Lion</a>""" 1075 self.assertContains(response, should_contain) 1076 1077 1053 1078 class TestInlineNotEditable(TestCase): 1054 1079 fixtures = ['admin-views-users.xml'] 1055 1080 -
tests/regressiontests/admin_views/models.py
184 184 def __unicode__(self): 185 185 return self.name 186 186 187 class Animal(models.Model): 188 title = models.CharField(max_length=20) 189 def __unicode__(self): 190 return self.title 191 192 class AnimalChangeList(admin.views.main.ChangeList): 193 def url_for_result(self, result): 194 return "custom/%s/" % admin.util.quote(getattr(result, self.pk_attname)) 195 187 196 class Account(models.Model): 188 197 """ 189 198 A simple, generic account encapsulating the information shared by all … … 218 227 BarAccountAdmin 219 228 ) 220 229 230 231 class AnimalAdmin(admin.ModelAdmin): 232 changelist_class = AnimalChangeList 233 234 221 235 class Subscriber(models.Model): 222 236 name = models.CharField(blank=False, max_length=80) 223 237 email = models.EmailField(blank=False, max_length=175) … … 335 349 admin.site.register(Persona, PersonaAdmin) 336 350 admin.site.register(Subscriber, SubscriberAdmin) 337 351 admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin) 352 admin.site.register(Animal, AnimalAdmin) 338 353 admin.site.register(OldSubscriber, OldSubscriberAdmin) 339 354 admin.site.register(Podcast, PodcastAdmin) 340 355 admin.site.register(Vodcast, VodcastAdmin) -
tests/regressiontests/modeladmin/models.py
952 952 ... inlines = [ValidationTestInline] 953 953 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 954 954 955 # changelist_class 956 957 >>> class ValidationTestModelAdmin(ModelAdmin): 958 ... changelist_class = object 959 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 960 Traceback (most recent call last): 961 ... 962 ImproperlyConfigured: 'ValidationTestModelAdmin.changelist_class' does not inherit from admin.views.main.ChangeList. 963 964 >>> from django.contrib.admin.views.main import ChangeList 965 >>> class ValidationTestChangeList(ChangeList): 966 ... def url_for_result(self, result): 967 ... return "custom/%s/" % quote(getattr(result, self.pk_attname)) 968 >>> class ValidationTestModelAdmin(ModelAdmin): 969 ... changelist_class = ValidationTestChangeList 970 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 971 955 972 """ 956 973 }