admin_actions.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. =========================
  2. Writing New Admin Actions
  3. =========================
  4. Misago Admin vs. Django Admin
  5. =============================
  6. Misago brings its own admin site just like Django `does <https://docs.djangoproject.com/en/1.6/#the-admin>`_. This means you have to make a decision which one your app will use for administration.
  7. If you intend to be sole user of your app, Django admin will propably be faster to get going. However if you plan for your app to be available to wider audience, its good for your admin interface to be part of Misago admin site. This will require you to write more code than intended, but will give your users more consistent experience and, in case for some languages, save them of quirkyness that comes with django admin automatic messages.
  8. Writing Admin Views
  9. ===================
  10. Registering in Misago Admin
  11. ===========================
  12. Misago Admin Site is just an hierarchy of links defined in apps and registered within ``misago.admin.site`` object.
  13. Registering urls under ``misago:admin`` namespace
  14. -------------------------------------------------
  15. Your admin links will live under ``misago:admin`` namespace, which means they have to be registered in it beforehand. Similiarly to Django, Misago uses small discovery routine which discovers modules that are expected to register their urls in admin.
  16. .. warning::
  17. Presented solution is only temporary. Starting with Django 1.7, you will have to make decision where to locate code that will register your links in Misago admin and call it within your app ``apps.py`` initializer.
  18. Depending on structure of your app and your tastes, this module can be one of following:
  19. * yourapp.adminurls module
  20. * yourapp.urls.admin module
  21. Each of those is checked, in this order. First one to be found is included in urlconf. Once file is found, code within it its executed with assumption that it will register namespaces and patters in Misago admin.
  22. Admin links are stored within instance of special object :py:class:`misago.admin.urlpatterns.URLPatterns` avaialable under ``misago.admin.urlpatterns``. This object exposes two methods as public api:
  23. .. function:: namespace(path, namespace, parent=None)
  24. Registers new namespace in admin links hierarchy.
  25. * **path** - Path prefix for links within this namespace. For example ``r'^users/'``.
  26. * **namespace** - Non-prefixed (eg. without ``misago:admin`` part) namespace name.
  27. * **parent** - Optional. Name of parent namespace (eg. ``users:accounts``).
  28. .. function:: patterns(namespace, *urlpatterns)
  29. Registers urlpatterns under defined namespace. Expects first argument to be name of namespace that defined links belong to (eg. ``users:accounts``). Every next argument is expected to be valid Django link created with ``url`` function from :py:mod:`django.conf.urls` module.
  30. .. note::
  31. ''misago:admin'' prefix of namespaces is implicit. Do not prefix namespaces passed as arguments to those functions with it.
  32. Registering urls in navigation
  33. ------------------------------
  34. Your urls have to be discoverable by your users. Easiest way is to do this is to display primary link to your admin in admin site navigation.
  35. This navigation is controlled by instance of the :py:class:`misago.admin.hierarchy.AdminHierarchyBuilder` class available under ``misago.admin.site`` path. This class has plenty of functions, but it's public api consists of one method:
  36. .. function:: add_node(parent='misago:admin', after=None, before=None,
  37. namespace=None, link=None, name=None, icon=None)
  38. This method accepts following named arguments:
  39. * **parent** - Name of parent namespace under which this action link is displayed.
  40. * **after** - Link before which one this one should be displayed.
  41. * **before** - Link after which one this one should be displayed.
  42. * **namespace** - This link namespace.
  43. * **link** - Link name.
  44. * **name** - Link title.
  45. * **icon** - Link icon (both `Glyphicons <http://getbootstrap.com/components/#glyphicons>`_ and `Font Awesome <http://fontawesome.io/icons/>`_ are supported).
  46. Only last three arguments are required. ``after`` and ``before`` arguments are exclusive. If you specify both, this will result in an error.
  47. Misago Admin supports three levels of hierarchy. Each level should corelate to new namespace nested under ``misago:admin``. Depending on complexity of your app's admin, it can define links that are one level deep, or three levels deep.