2009-01-14 21:22:25 +01:00
|
|
|
"""
|
|
|
|
A second, custom AdminSite -- see tests.CustomAdminSiteTests.
|
|
|
|
"""
|
2011-10-13 20:51:33 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2011-09-12 00:36:16 +02:00
|
|
|
from django.conf.urls import patterns
|
2009-01-14 21:22:25 +01:00
|
|
|
from django.contrib import admin
|
|
|
|
from django.http import HttpResponse
|
2012-02-09 19:57:40 +01:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.contrib.auth.admin import UserAdmin
|
2009-01-14 21:22:25 +01:00
|
|
|
|
2011-10-13 20:51:33 +02:00
|
|
|
from . import models, forms, admin as base_admin
|
|
|
|
|
2009-01-14 21:22:25 +01:00
|
|
|
|
|
|
|
class Admin2(admin.AdminSite):
|
2010-12-02 01:44:35 +01:00
|
|
|
login_form = forms.CustomAdminAuthenticationForm
|
2009-01-14 21:22:25 +01:00
|
|
|
login_template = 'custom_admin/login.html'
|
2010-01-13 00:34:46 +01:00
|
|
|
logout_template = 'custom_admin/logout.html'
|
2012-12-04 00:39:03 +01:00
|
|
|
index_template = ['custom_admin/index.html'] # a list, to test fix for #18697
|
2010-01-13 00:34:46 +01:00
|
|
|
password_change_template = 'custom_admin/password_change_form.html'
|
|
|
|
password_change_done_template = 'custom_admin/password_change_done.html'
|
2009-07-16 18:16:13 +02:00
|
|
|
|
2009-01-14 21:22:25 +01:00
|
|
|
# A custom index view.
|
|
|
|
def index(self, request, extra_context=None):
|
|
|
|
return super(Admin2, self).index(request, {'foo': '*bar*'})
|
2009-07-16 18:16:13 +02:00
|
|
|
|
2009-01-14 21:22:25 +01:00
|
|
|
def get_urls(self):
|
|
|
|
return patterns('',
|
|
|
|
(r'^my_view/$', self.admin_view(self.my_view)),
|
|
|
|
) + super(Admin2, self).get_urls()
|
2009-07-16 18:16:13 +02:00
|
|
|
|
2009-01-14 21:22:25 +01:00
|
|
|
def my_view(self, request):
|
|
|
|
return HttpResponse("Django is a magical pony!")
|
2009-07-16 18:16:13 +02:00
|
|
|
|
2012-02-09 19:57:40 +01:00
|
|
|
|
|
|
|
class UserLimitedAdmin(UserAdmin):
|
|
|
|
# used for testing password change on a user not in queryset
|
2013-03-08 15:15:23 +01:00
|
|
|
def get_queryset(self, request):
|
|
|
|
qs = super(UserLimitedAdmin, self).get_queryset(request)
|
2012-02-09 19:57:40 +01:00
|
|
|
return qs.filter(is_superuser=False)
|
|
|
|
|
|
|
|
|
2012-12-04 00:39:03 +01:00
|
|
|
class CustomPwdTemplateUserAdmin(UserAdmin):
|
|
|
|
change_user_password_template = ['admin/auth/user/change_password.html'] # a list, to test fix for #18697
|
|
|
|
|
|
|
|
|
2009-01-14 21:22:25 +01:00
|
|
|
site = Admin2(name="admin2")
|
|
|
|
|
2011-09-20 20:16:49 +02:00
|
|
|
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)
|
2012-02-09 19:57:40 +01:00
|
|
|
site.register(User, UserLimitedAdmin)
|
2012-07-22 03:10:24 +02:00
|
|
|
site.register(models.UndeletableObject, base_admin.UndeletableObjectAdmin)
|
2012-09-08 17:18:08 +02:00
|
|
|
site.register(models.Simple, base_admin.AttributeErrorRaisingAdmin)
|
2012-12-04 00:39:03 +01:00
|
|
|
|
|
|
|
simple_site = Admin2(name='admin4')
|
|
|
|
simple_site.register(User, CustomPwdTemplateUserAdmin)
|