PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/admin_views/customadmin.py

https://code.google.com/p/mango-py/
Python | 36 lines | 28 code | 4 blank | 4 comment | 0 complexity | 25dc4e2c0241fd60f67a227bcfbbbfcb MD5 | raw file
 1"""
 2A second, custom AdminSite -- see tests.CustomAdminSiteTests.
 3"""
 4from django.conf.urls.defaults import patterns
 5from django.contrib import admin
 6from django.http import HttpResponse
 7
 8import models, forms
 9
10class Admin2(admin.AdminSite):
11    login_form = forms.CustomAdminAuthenticationForm
12    login_template = 'custom_admin/login.html'
13    logout_template = 'custom_admin/logout.html'
14    index_template = 'custom_admin/index.html'
15    password_change_template = 'custom_admin/password_change_form.html'
16    password_change_done_template = 'custom_admin/password_change_done.html'
17
18    # A custom index view.
19    def index(self, request, extra_context=None):
20        return super(Admin2, self).index(request, {'foo': '*bar*'})
21
22    def get_urls(self):
23        return patterns('',
24            (r'^my_view/$', self.admin_view(self.my_view)),
25        ) + super(Admin2, self).get_urls()
26
27    def my_view(self, request):
28        return HttpResponse("Django is a magical pony!")
29
30site = Admin2(name="admin2")
31
32site.register(models.Article, models.ArticleAdmin)
33site.register(models.Section, inlines=[models.ArticleInline])
34site.register(models.Thing, models.ThingAdmin)
35site.register(models.Fabric, models.FabricAdmin)
36site.register(models.ChapterXtra1, models.ChapterXtra1Admin)