mirror of
https://github.com/django/django.git
synced 2024-11-19 07:54:07 +00:00
ccd1bb0d81
During the new-admin changes, catching of AttributeError was added to the admin. This patch removes that as it's no longer possible to add a value to a ModelAdmin that is not available. Adding an attribute that can not be called causes an ImproperlyConfigured exception to be raised.
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
"""
|
|
A second, custom AdminSite -- see tests.CustomAdminSiteTests.
|
|
"""
|
|
from __future__ import absolute_import
|
|
|
|
from django.conf.urls import patterns
|
|
from django.contrib import admin
|
|
from django.http import HttpResponse
|
|
from django.contrib.auth.models import User
|
|
from django.contrib.auth.admin import UserAdmin
|
|
|
|
from . import models, forms, admin as base_admin
|
|
|
|
|
|
class Admin2(admin.AdminSite):
|
|
login_form = forms.CustomAdminAuthenticationForm
|
|
login_template = 'custom_admin/login.html'
|
|
logout_template = 'custom_admin/logout.html'
|
|
index_template = 'custom_admin/index.html'
|
|
password_change_template = 'custom_admin/password_change_form.html'
|
|
password_change_done_template = 'custom_admin/password_change_done.html'
|
|
|
|
# A custom index view.
|
|
def index(self, request, extra_context=None):
|
|
return super(Admin2, self).index(request, {'foo': '*bar*'})
|
|
|
|
def get_urls(self):
|
|
return patterns('',
|
|
(r'^my_view/$', self.admin_view(self.my_view)),
|
|
) + super(Admin2, self).get_urls()
|
|
|
|
def my_view(self, request):
|
|
return HttpResponse("Django is a magical pony!")
|
|
|
|
|
|
class UserLimitedAdmin(UserAdmin):
|
|
# used for testing password change on a user not in queryset
|
|
def queryset(self, request):
|
|
qs = super(UserLimitedAdmin, self).queryset(request)
|
|
return qs.filter(is_superuser=False)
|
|
|
|
|
|
site = Admin2(name="admin2")
|
|
|
|
site.register(models.Article, base_admin.ArticleAdmin)
|
|
site.register(models.Section, inlines=[base_admin.ArticleInline])
|
|
site.register(models.Thing, base_admin.ThingAdmin)
|
|
site.register(models.Fabric, base_admin.FabricAdmin)
|
|
site.register(models.ChapterXtra1, base_admin.ChapterXtra1Admin)
|
|
site.register(User, UserLimitedAdmin)
|
|
site.register(models.UndeletableObject, base_admin.UndeletableObjectAdmin)
|
|
site.register(models.Simple, base_admin.AttributeErrorRaisingAdmin)
|