2021-04-21 12:27:18 +00:00
|
|
|
from django.urls import reverse
|
2023-11-17 12:25:13 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2015-05-07 19:00:02 +00:00
|
|
|
from fluent_dashboard import dashboard, appsettings
|
2015-04-26 13:53:00 +00:00
|
|
|
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):
|
2015-05-07 19:00:02 +00:00
|
|
|
""" Provides support for custom default icons """
|
2015-05-07 14:09:37 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.icons = kwargs.pop('icons')
|
|
|
|
super(AppDefaultIconList, self).__init__(*args, **kwargs)
|
2021-04-21 12:27:18 +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):
|
2015-05-07 19:00:02 +00:00
|
|
|
""" Gets application modules from services, accounts and administration registries """
|
2021-04-21 12:27:18 +00:00
|
|
|
|
2015-10-07 22:05:00 +00:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(dashboard.FluentIndexDashboard, self).__init__(**kwargs)
|
|
|
|
self.children.append(self.get_personal_module())
|
|
|
|
self.children.extend(self.get_application_modules())
|
|
|
|
recent_actions = self.get_recent_actions_module()
|
|
|
|
recent_actions.enabled = True
|
|
|
|
self.children.append(recent_actions)
|
2021-04-21 12:27:18 +00:00
|
|
|
|
2015-05-07 14:09:37 +00:00
|
|
|
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({
|
2015-05-07 19:00:02 +00:00
|
|
|
'models': [
|
|
|
|
{
|
|
|
|
'add_url': add_url,
|
|
|
|
'app_name': app_name,
|
|
|
|
'change_url': url,
|
|
|
|
'name': name,
|
|
|
|
'title': options.get('verbose_name_plural')
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'name': app_name,
|
|
|
|
'title': options.get('verbose_name_plural'),
|
|
|
|
'url': add_url,
|
2015-05-07 14:09:37 +00:00
|
|
|
})
|
2021-04-21 12:27:18 +00:00
|
|
|
|
2015-04-26 13:53:00 +00:00
|
|
|
def get_application_modules(self):
|
2015-05-07 14:09:37 +00:00
|
|
|
modules = []
|
|
|
|
# Honor settings override, hacky. I Know
|
|
|
|
if appsettings.FLUENT_DASHBOARD_APP_GROUPS[0][0] != _('CMS'):
|
|
|
|
modules = super(OrchestraIndexDashboard, self).get_application_modules()
|
2015-10-07 22:05:00 +00:00
|
|
|
for register in (accounts, services, administration):
|
2015-05-07 14:09:37 +00:00
|
|
|
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
|