Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1 | #sites.py |
| 2 | |
| 3 | from django.contrib.admin.sites import AdminSite |
| 4 | |
| 5 | |
| 6 | class AdminMixin(object): |
| 7 | """Mixin for AdminSite to allow custom dashboard views.""" |
| 8 | |
| 9 | def __init__(self, *args, **kwargs): |
| 10 | return super(AdminMixin, self).__init__(*args, **kwargs) |
| 11 | |
| 12 | def get_urls(self): |
| 13 | """Add our dashboard view to the admin urlconf. Deleted the default index.""" |
| 14 | from django.conf.urls import patterns, url |
| 15 | from views import DashboardWelcomeView |
| 16 | |
| 17 | urls = super(AdminMixin, self).get_urls() |
| 18 | del urls[0] |
| 19 | custom_url = patterns('', |
| 20 | url(r'^$', self.admin_view(DashboardWelcomeView.as_view()), |
| 21 | name="index") |
| 22 | ) |
| 23 | |
| 24 | return custom_url + urls |
| 25 | |
| 26 | |
| 27 | class SitePlus(AdminMixin, AdminSite): |
| 28 | """ |
| 29 | A Django AdminSite with the AdminMixin to allow registering custom |
| 30 | dashboard view. |
| 31 | """ |