django-orchestra-test/orchestra/admin/dashboard.py

46 lines
1.8 KiB
Python
Raw Normal View History

2015-04-29 10:51:30 +00:00
from django.core.urlresolvers import reverse
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
from orchestra.core import services
2015-04-26 13:53:00 +00:00
class OrchestraIndexDashboard(dashboard.FluentIndexDashboard):
2015-04-29 10:51:30 +00:00
_registry = {}
@classmethod
def register_link(cls, module, view_name, title):
registered = cls._registry.get(module, [])
registered.append((view_name, title))
cls._registry[module] = registered
2015-04-26 13:53:00 +00:00
def get_application_modules(self):
modules = super(OrchestraIndexDashboard, self).get_application_modules()
models = []
for model, options in services.get().items():
if options.get('menu', True):
models.append("%s.%s" % (model.__module__, model._meta.object_name))
for module in modules:
2015-04-29 10:51:30 +00:00
registered = self._registry.get(module.title, None)
if registered:
for view_name, title in registered:
# This values are shit, but it is how fluent dashboard will look for the icon
app_name, name = view_name.split('_')[:-1]
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': title }],
'name': app_name,
'title': title,
'url': add_url,
})
2015-04-26 13:53:00 +00:00
service_icon_list = CmsAppIconList('Services', models=models, collapsible=True)
modules.append(service_icon_list)
return modules