This section describe the API of the Grappelli dashboard and dashboard modules.
Base class for dashboards. The Dashboard class is a simple python list that has three additional properties:
Here’s an example of a custom dashboard:
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from admin_tools.dashboard import modules, Dashboard
class MyDashboard(Dashboard):
def __init__(self, **kwargs):
# append an app list module for "Applications"
self.children.append(modules.AppList(
title=_('Applications'),
column=1,
collapsible=True,
exclude=('django.contrib.*',),
))
# append an app list module for "Administration"
self.children.append(modules.AppList(
title=_('Administration'),
column=1,
collapsible=True,
models=('django.contrib.*',),
))
# append a recent actions module
self.children.append(modules.RecentActions(
title=_('Recent Actions'),
column=2,
collapsible=False,
limit=5,
))
Base class for all dashboard modules. Dashboard modules have the following properties:
Represents a group of modules:
from grappelli.dashboard import modules, Dashboard
class MyDashboard(Dashboard):
def __init__(self, **kwargs):
Dashboard.__init__(self, **kwargs)
self.children.append(modules.Group(
title="My group",
column=1,
collapsible=True,
children=[
modules.AppList(
title='Administration',
models=('django.contrib.*',)
),
modules.AppList(
title='Applications',
exclude=('django.contrib.*',)
)
]
))
A module that displays a list of links. As well as the DashboardModule properties, the LinkList takes an extra keyword argument:
Link list modules children are simple python dictionaries that can have the following keys:
Children can also be iterables (lists or tuples) of length 2, 3 or 4.
Here’s a small example of building a link list module:
from grappelli.dashboard import modules, Dashboard
class MyDashboard(Dashboard):
def __init__(self, **kwargs):
Dashboard.__init__(self, **kwargs)
self.children.append(modules.LinkList(
layout='inline',
column=2,
children=(
{
'title': 'Python website',
'url': 'http://www.python.org',
'external': True,
'description': 'Python programming language rocks !',
},
['Django website', 'http://www.djangoproject.com', True],
['Some internal link', '/some/internal/link/'],
)
))
Module that lists installed apps and their models. As well as the DashboardModule properties, the AppList has two extra properties:
If no models/exclude list is provided, all apps are shown.
Here’s a small example of building an app list module:
from grappelli.dashboard import modules, Dashboard
class MyDashboard(Dashboard):
def __init__(self, **kwargs):
Dashboard.__init__(self, **kwargs)
# will only list the django.contrib apps
self.children.append(modules.AppList(
title='Administration',
column=1,
models=('django.contrib.*',)
))
# will list all apps except the django.contrib ones
self.children.append(modules.AppList(
title='Applications',
column=1,
exclude=('django.contrib.*',)
))
Note
Note that this module takes into account user permissions, for example, if a user has no rights to change or add a Group, then the django.contrib.auth.Group model line will not be displayed.
Module that lists a set of models. As well as the DashboardModule properties, the ModelList takes two extra arguments:
Here’s a small example of building a model list module:
from grappelli.dashboard import modules, Dashboard
class MyDashboard(Dashboard):
def __init__(self, **kwargs):
Dashboard.__init__(self, **kwargs)
self.children.append(modules.ModelList(
title='Applications',
column=1,
models=('django.contrib.*',)
))
Note
Note that this module takes into account user permissions, for example, if a user has no rights to change or add a Group, then the django.contrib.auth.Group model line will not be displayed.
Module that lists the recent actions for the current user. As well as the DashboardModule properties, the RecentActions takes three extra keyword arguments:
Here’s a small example of building a recent actions module:
from grappelli.dashboard import modules, Dashboard
class MyDashboard(Dashboard):
def __init__(self, **kwargs):
Dashboard.__init__(self, **kwargs)
self.children.append(modules.RecentActions(
title='Django CMS recent actions',
column=3,
limit=5,
))
Class that represents a feed dashboard module.
Note
This class requires the Universal Feed Parser module, so you’ll need to install it.
As well as the DashboardModule properties, the Feed takes two extra keyword arguments:
Here’s a small example of building a recent actions module:
from grappelli.dashboard import modules, Dashboard
class MyDashboard(Dashboard):
def __init__(self, **kwargs):
Dashboard.__init__(self, **kwargs)
self.children.append(modules.Feed(
title=_('Latest Django News'),
feed_url='http://www.djangoproject.com/rss/weblog/',
column=3,
limit=5,
))