pages.rst 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. ===============
  2. Extending Pages
  3. ===============
  4. Certain pages in misago are simple containers for sections:
  5. * User Control Panel
  6. * User Profiles List
  7. * User Profile
  8. Each of those pages consists of its own layout and list of sections. For example, User Profile layout displays user name, information about user status, and sections (tabs) with lists of user threads, posts, followers and likes.
  9. Each section is associated to instance of special object, :py:class:`misago.core.page.Page`, which contains list of all sections belonging to it. Those instances are :py:object:`misago.users.sites.usercp`, :py:object:`misago.users.sites.users_list` and :py:object:`misago.users.sites.user_profile`.
  10. :py:class:`misago.core.page.Page` instances expose following API:
  11. .. function:: add_section(link, after=None, before=None, visible_if=None, get_metadata=None, **kwargs)
  12. Adds section to page. ``after`` and ``before`` arguments should be value of other page ``link``. ``visible_if`` argument accepts callable that will be called with args passed to ``get_pages`` function on page render to resolve if link to page should be displayed. ``get_metadata`` can be callable returning additional computed metadata for this page. All other values passed to function call get preserved in order to make it easy for 3rd party developers to reuse mechanic for their apps.
  13. ``visible_if`` and ``get_metadata`` functions are called with arguments that were passed to ``get_sections`` method.
  14. .. function:: get_sections(request, *args)
  15. Returns list of sections assigned to this page. Each section is a dict of kwargs passed to ``add_section`` with additional ``is_active`` argument that controls if selected page is displayed one and ``metadata`` dict if one is defined.
  16. .. function:: get_default_link()
  17. Returns default link name that should be used as argument for ``{% url %}`` template tag.
  18. Default links for Misago user pages are available in templates through following variables:
  19. * **USERCP_URL** - Default link to user control panel site.
  20. * **USERS_LIST_URL** - Default link to users lists site.
  21. * **USER_PROFILE_URL** - Default link to user profile site.