2015-04-29 10:51:30 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
2015-05-07 14:09:37 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2015-04-26 13:53:00 +00:00
|
|
|
from fluent_dashboard import dashboard
|
|
|
|
from fluent_dashboard.modules import CmsAppIconList
|
2014-05-08 16:59:35 +00:00
|
|
|
|
2015-05-07 14:09:37 +00:00
|
|
|
from orchestra.core import services, accounts, administration
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
|
2015-05-07 14:09:37 +00:00
|
|
|
class AppDefaultIconList(CmsAppIconList):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.icons = kwargs.pop('icons')
|
|
|
|
super(AppDefaultIconList, self).__init__(*args, **kwargs)
|
2015-04-29 10:51:30 +00:00
|
|
|
|
2015-05-07 14:09:37 +00:00
|
|
|
def get_icon_for_model(self, app_name, model_name, default=None):
|
|
|
|
icon = self.icons.get('.'.join((app_name, model_name)))
|
|
|
|
return super(AppDefaultIconList, self).get_icon_for_model(app_name, model_name, default=icon)
|
|
|
|
|
|
|
|
|
|
|
|
class OrchestraIndexDashboard(dashboard.FluentIndexDashboard):
|
|
|
|
def process_registered_view(self, module, view_name, options):
|
|
|
|
app_name, name = view_name.split('_')[:-1]
|
|
|
|
module.icons['.'.join((app_name, name))] = options.get('icon')
|
|
|
|
url = reverse('admin:' + view_name)
|
|
|
|
add_url = '/'.join(url.split('/')[:-2])
|
|
|
|
module.children.append({
|
|
|
|
'models': [{
|
|
|
|
'add_url': add_url,
|
|
|
|
'app_name': app_name,
|
|
|
|
'change_url': url,
|
|
|
|
'name': name,
|
|
|
|
'title': options.get('verbose_name')}],
|
|
|
|
'name': app_name,
|
|
|
|
'title': options.get('verbose_name'),
|
|
|
|
'url': add_url,
|
|
|
|
})
|
2015-04-29 10:51:30 +00:00
|
|
|
|
2015-04-26 13:53:00 +00:00
|
|
|
def get_application_modules(self):
|
2015-05-07 14:09:37 +00:00
|
|
|
from fluent_dashboard import appsettings
|
|
|
|
modules = []
|
|
|
|
# Honor settings override, hacky. I Know
|
|
|
|
if appsettings.FLUENT_DASHBOARD_APP_GROUPS[0][0] != _('CMS'):
|
|
|
|
modules = super(OrchestraIndexDashboard, self).get_application_modules()
|
|
|
|
for register in (accounts, administration, services):
|
|
|
|
title = register.verbose_name
|
|
|
|
models = []
|
|
|
|
icons = {}
|
|
|
|
views = []
|
|
|
|
for model, options in register.get().items():
|
|
|
|
if isinstance(model, str):
|
|
|
|
views.append((model, options))
|
|
|
|
elif options.get('dashboard', True):
|
|
|
|
opts = model._meta
|
|
|
|
label = "%s.%s" % (model.__module__, opts.object_name)
|
|
|
|
models.append(label)
|
|
|
|
label = '.'.join((opts.app_label, opts.model_name))
|
|
|
|
icons[label] = options.get('icon')
|
|
|
|
module = AppDefaultIconList(title, models=models, icons=icons, collapsible=True)
|
|
|
|
for view_name, options in views:
|
|
|
|
self.process_registered_view(module, view_name, options)
|
|
|
|
modules.append(module)
|
2015-04-26 13:53:00 +00:00
|
|
|
return modules
|