PageRenderTime 61ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  1. """
  2. A second, custom AdminSite -- see tests.CustomAdminSiteTests.
  3. """
  4. from django.conf.urls.defaults import patterns
  5. from django.contrib import admin
  6. from django.http import HttpResponse
  7. import models, forms
  8. class Admin2(admin.AdminSite):
  9. login_form = forms.CustomAdminAuthenticationForm
  10. login_template = 'custom_admin/login.html'
  11. logout_template = 'custom_admin/logout.html'
  12. index_template = 'custom_admin/index.html'
  13. password_change_template = 'custom_admin/password_change_form.html'
  14. password_change_done_template = 'custom_admin/password_change_done.html'
  15. # A custom index view.
  16. def index(self, request, extra_context=None):
  17. return super(Admin2, self).index(request, {'foo': '*bar*'})
  18. def get_urls(self):
  19. return patterns('',
  20. (r'^my_view/$', self.admin_view(self.my_view)),
  21. ) + super(Admin2, self).get_urls()
  22. def my_view(self, request):
  23. return HttpResponse("Django is a magical pony!")
  24. site = Admin2(name="admin2")
  25. site.register(models.Article, models.ArticleAdmin)
  26. site.register(models.Section, inlines=[models.ArticleInline])
  27. site.register(models.Thing, models.ThingAdmin)
  28. site.register(models.Fabric, models.FabricAdmin)
  29. site.register(models.ChapterXtra1, models.ChapterXtra1Admin)