dashboard_custom.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ================
  2. Custom Dashboard
  3. ================
  4. .. note::
  5. Django JET Dashboard tries to be as compatible as possible with django-admin-tools dashboard so that
  6. django-admin-tools modules could be easily ported to Django JET. In most cases in will be enough to
  7. change python imports and remove extending in modules templates.
  8. Dashboard represents ``Dashboard`` class instance with ``DashboardModule`` class instances as its children.
  9. Any custom **Dashboard** class should inherit ``jet.dashboard.dashboard.Dashboard``
  10. and use ``init_with_context`` to fill it with widgets. You should add your widgets
  11. to ``children`` and ``available_children`` attributes.
  12. Before continue make sure you have completed :doc:`install_dashboard`.
  13. Set Up Custom Dashboard
  14. -----------------------
  15. * Create ``dashboard.py`` in any suitable location (e.g., in your project root) with the following content:
  16. .. code-block:: python
  17. from django.utils.translation import ugettext_lazy as _
  18. from jet.dashboard import modules
  19. from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
  20. class CustomIndexDashboard(Dashboard):
  21. columns = 3
  22. def init_with_context(self, context):
  23. self.available_children.append(modules.LinkList)
  24. self.children.append(modules.LinkList(
  25. _('Support'),
  26. children=[
  27. {
  28. 'title': _('Django documentation'),
  29. 'url': 'http://docs.djangoproject.com/',
  30. 'external': True,
  31. },
  32. {
  33. 'title': _('Django "django-users" mailing list'),
  34. 'url': 'http://groups.google.com/group/django-users',
  35. 'external': True,
  36. },
  37. {
  38. 'title': _('Django irc channel'),
  39. 'url': 'irc://irc.freenode.net/django',
  40. 'external': True,
  41. },
  42. ],
  43. column=0,
  44. order=0
  45. ))
  46. * Add to your settings.py path to created ``dashboard.py`` (example for ``dashboard.py`` in project root):
  47. .. code:: python
  48. JET_INDEX_DASHBOARD = 'dashboard.CustomIndexDashboard'
  49. That's all, now you have dashboard with only one widget - ``LinkList``. Dashboard reset may be needed
  50. if your had another dashboard already rendered for any user. Visit :doc:`dashboard_modules` to learn
  51. other widgets you can add to your custom dashboard or :doc:`dashboard_custom_module` to create your own.