Ticket #12004: fix12004.patch

File fix12004.patch, 4.6 KB (added by Matthias Kestenholz, 14 years ago)
  • django/contrib/admin/sites.py

    diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
    index d0d6473..f7de7df 100644
    a b class AdminSite(object):  
    7474        if isinstance(model_or_iterable, ModelBase):
    7575            model_or_iterable = [model_or_iterable]
    7676        for model in model_or_iterable:
     77            if model._meta.abstract:
     78                raise ImproperlyConfigured('Unable to register abstract model %s' % model.__name__)
     79
    7780            if model in self._registry:
    7881                raise AlreadyRegistered('The model %s is already registered' % model.__name__)
    7982
  • new file tests/regressiontests/admin_views/abstractadmin.py

    diff --git a/tests/regressiontests/admin_views/abstractadmin.py b/tests/regressiontests/admin_views/abstractadmin.py
    new file mode 100644
    index 0000000..71d372b
    - +  
     1"""
     2see tests.AbstractAdminTest
     3"""
     4from django.contrib import admin
     5
     6import models
     7
     8site = admin.AdminSite(name="abstractadmin")
     9
     10site.register(models.Pizza)
     11
     12def do_register():
     13    # This method should raise an ImproperlyConfigured exception
     14    site.register(models.AbstractPizza)
  • tests/regressiontests/admin_views/models.py

    diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
    index b25a9b9..946b6a7 100644
    a b class CyclicTwo(models.Model):  
    573573class Topping(models.Model):
    574574    name = models.CharField(max_length=20)
    575575
    576 class Pizza(models.Model):
     576class AbstractPizza(models.Model):
    577577    name = models.CharField(max_length=20)
     578
     579    class Meta:
     580        abstract = True
     581
     582class Pizza(AbstractPizza):
    578583    toppings = models.ManyToManyField('Topping')
    579584
    580585class PizzaAdmin(admin.ModelAdmin):
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 725369a..15845b8 100644
    a b  
    33import re
    44import datetime
    55from django.conf import settings
     6from django.core.exceptions import ImproperlyConfigured
    67from django.core.files import temp as tempfile
    78from django.contrib.auth import admin # Register auth models with the admin.
    89from django.contrib.auth.models import User, Permission, UNUSABLE_PASSWORD
    from models import Article, BarAccount, CustomArticle, EmptyModel, \  
    2425    FooAccount, Gallery, ModelWithStringPrimaryKey, \
    2526    Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
    2627    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
    27     Category, Post, Plot, FunkyTag
     28    Category, Post, Plot, FunkyTag, AbstractPizza
    2829
    2930
    3031class AdminViewBasicTest(TestCase):
    class CustomModelAdminTest(AdminViewBasicTest):  
    360361        response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
    361362        self.assert_(response.content == "Django is a magical pony!", response.content)
    362363
     364class AbstractAdminTest(TestCase):
     365    fixtures = ['admin-views-users.xml']
     366
     367    urlbit = "abstractadmin"
     368
     369    def setUp(self):
     370        self.old_language_code = settings.LANGUAGE_CODE
     371        self.client.login(username='super', password='secret')
     372
     373    def tearDown(self):
     374        settings.LANGUAGE_CODE = self.old_language_code
     375        self.client.logout()
     376
     377    def test_abstract_register(self):
     378        """
     379        Regression test for #12004:
     380        Exception is raised when trying to register an abstract model
     381        """
     382
     383        import abstractadmin
     384
     385        # Smoke test to determine whether admin site works at all
     386        response = self.client.get('/test_admin/abstractadmin/admin_views/pizza/')
     387        self.failUnlessEqual(response.status_code, 200)
     388
     389        self.assertRaises(ImproperlyConfigured, abstractadmin.do_register)
     390
    363391def get_perm(Model, perm):
    364392    """Return the permission object, for the Model"""
    365393    ct = ContentType.objects.get_for_model(Model)
  • tests/regressiontests/admin_views/urls.py

    diff --git a/tests/regressiontests/admin_views/urls.py b/tests/regressiontests/admin_views/urls.py
    index f3f1fbd..b7aeba5 100644
    a b from django.conf.urls.defaults import *  
    22from django.contrib import admin
    33import views
    44import customadmin
     5import abstractadmin
    56
    67urlpatterns = patterns('',
    78    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
    89    (r'^admin/secure-view/$', views.secure_view),
    910    (r'^admin/', include(admin.site.urls)),
    1011    (r'^admin2/', include(customadmin.site.urls)),
     12    (r'^abstractadmin/', include(abstractadmin.site.urls)),
    1113)
Back to Top