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 |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 15 | from views import DashboardWelcomeView, DashboardAjaxView |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 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()), |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 21 | name="index"), |
| 22 | url(r'^hpcdashboard/', self.admin_view(DashboardAjaxView.as_view()), |
| 23 | name="hpcdashboard") |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | return custom_url + urls |
| 27 | |
| 28 | |
| 29 | class SitePlus(AdminMixin, AdminSite): |
| 30 | """ |
| 31 | A Django AdminSite with the AdminMixin to allow registering custom |
| 32 | dashboard view. |
| 33 | """ |