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 |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 15 | from views import DashboardWelcomeView, DashboardAjaxView, SimulatorView, DashboardSummaryAjaxView, DashboardAddOrRemoveSliverView, DashboardUserSiteView, DashboardAnalyticsAjaxView |
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('', |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 20 | url(r'^$', self.admin_view(DashboardWelcomeView.as_view()), |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 21 | name="index"), |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 22 | url(r'^hpcdashuserslices/', self.admin_view(DashboardUserSiteView.as_view()), |
| 23 | name="hpcdashuserslices"), |
| 24 | url(r'^hpcdashboard/', self.admin_view(DashboardAjaxView.as_view()), # DEPRECATED |
| 25 | name="hpcdashboard"), |
| 26 | url(r'^simulator/', self.admin_view(SimulatorView.as_view()), |
| 27 | name="simulator"), |
| 28 | url(r'^hpcsummary/', self.admin_view(DashboardSummaryAjaxView.as_view()), # DEPRECATED |
| 29 | name="hpcsummary"), |
Scott Baker | 27412cd | 2014-03-27 09:01:28 -0700 | [diff] [blame] | 30 | url(r'^analytics/(?P<name>\w+)/$', DashboardAnalyticsAjaxView.as_view(), |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 31 | name="analytics"), |
| 32 | url(r'^dashboardaddorremsliver/$', self.admin_view(DashboardAddOrRemoveSliverView.as_view()), |
| 33 | name="addorremsliver") |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | return custom_url + urls |
| 37 | |
| 38 | |
| 39 | class SitePlus(AdminMixin, AdminSite): |
| 40 | """ |
| 41 | A Django AdminSite with the AdminMixin to allow registering custom |
| 42 | dashboard view. |
| 43 | """ |