django-fobi/examples/simple/admin_tools_dashboard/menu.py

63 lines
2 KiB
Python
Raw Normal View History

2014-10-11 03:54:24 +00:00
"""
This file was generated with the custommenu management command, it contains
the classes for the admin menu, you can customize this class as you want.
To activate your custom menu add the following to your settings.py::
ADMIN_TOOLS_MENU = 'admin_tools_dashboard.menu.CustomMenu'
"""
2022-07-12 20:53:28 +00:00
from admin_tools.menu import Menu, items
from django.conf import settings
from django.urls import reverse
2020-01-11 00:46:53 +00:00
from django.utils.translation import gettext_lazy as _
2014-10-11 03:54:24 +00:00
from . import conf
2022-07-12 20:53:28 +00:00
__all__ = ("CustomMenu",)
2014-10-11 03:54:24 +00:00
class CustomMenu(Menu):
"""Custom Menu."""
2014-10-11 03:54:24 +00:00
def __init__(self, **kwargs):
Menu.__init__(self, **kwargs)
self.children += [
2022-07-12 20:53:28 +00:00
items.MenuItem(_("Dashboard"), reverse("admin:index")),
2014-10-11 03:54:24 +00:00
]
# Foo
2022-07-12 20:53:28 +00:00
self.children.append(items.ModelList(_("Foo"), models=conf.foo_apps))
2014-10-11 03:54:24 +00:00
# Fobi
self.children.append(
items.MenuItem(
2022-07-12 20:53:28 +00:00
_("Fobi"),
children=[
2022-07-12 20:53:28 +00:00
items.ModelList(_("Plugins"), models=conf.fobi_plugins),
items.ModelList(_("Forms"), models=conf.fobi_forms),
items.ModelList(_("Data"), models=conf.fobi_data),
],
)
)
2014-10-11 03:54:24 +00:00
2022-07-12 20:53:28 +00:00
if "feincms" in settings.INSTALLED_APPS:
# FeinCMS pages integration
self.children.append(
2022-07-12 20:53:28 +00:00
items.AppList(_("FeinCMS Pages"), models=conf.feincms_pages)
)
2022-07-12 20:53:28 +00:00
if "cms" in settings.INSTALLED_APPS:
# DjangoCMS pages integration
self.children.append(
2022-07-12 20:53:28 +00:00
items.AppList(_("DjangoCMS Pages"), models=conf.djangocms_pages)
)
2014-10-11 03:54:24 +00:00
# append an app list module for "Administration"
self.children.append(
2022-07-12 20:53:28 +00:00
items.AppList(_("Administration"), models=["django.contrib.*"])
)
2014-10-11 03:54:24 +00:00
def init_with_context(self, context):
"""Use this method if you need to access the request context."""
2014-10-11 03:54:24 +00:00
return super(CustomMenu, self).init_with_context(context)