hooks.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. .. _hooks:
  2. Hooks
  3. =====
  4. In FlaskBB we distinguish from `Python Hooks <#python-hooks>`_ and
  5. `Template Hooks <#template-hooks>`_.
  6. Python Hooks are prefixed with ``flaskbb_`` and called are called in Python
  7. files whereas Template Hooks have to be prefixed with ``flaskbb_tpl_`` and are
  8. executed in the templates.
  9. If you miss a hook, feel free to open a new issue or create a pull
  10. request. The pull request should always contain a entry in this document
  11. with a small example.
  12. A hook needs a hook specification which are defined in
  13. :mod:`flaskbb.plugins.spec`. All hooks have to be prefixed with
  14. ``flaskbb_`` and template hooks with ``flaskbb_tpl_``.
  15. Be sure to also check out the :ref:`api` documentation for interfaces that
  16. interact with these plugins in interesting ways.
  17. Python Hooks
  18. ------------
  19. .. currentmodule:: flaskbb.plugins.spec
  20. Application Startup Hooks
  21. ~~~~~~~~~~~~~~~~~~~~~~~~~
  22. Application startup hooks are called when the application is created,
  23. either through a WSGI server (uWSGI or gunicorn for example) or by
  24. the ``flaskbb`` command.
  25. Unless noted, all FlaskBB hooks are called after the relevant builtin
  26. FlaskBB setup has run (e.g. ``flaskbb_load_blueprints`` is called after
  27. all standard FlaskBB blueprints have been loaded).
  28. The hooks below are listed in the order they are called.
  29. .. autofunction:: flaskbb_extensions
  30. .. autofunction:: flaskbb_load_blueprints
  31. .. autofunction:: flaskbb_jinja_directives
  32. .. autofunction:: flaskbb_request_processors
  33. .. autofunction:: flaskbb_errorhandlers
  34. .. autofunction:: flaskbb_load_migrations
  35. .. autofunction:: flaskbb_load_translations
  36. .. autofunction:: flaskbb_load_post_markdown_class
  37. .. autofunction:: flaskbb_load_nonpost_markdown_class
  38. .. autofunction:: flaskbb_additional_setup
  39. FlaskBB CLI Hooks
  40. ~~~~~~~~~~~~~~~~~
  41. These hooks are only invoked when using the ``flaskbb``
  42. CLI.
  43. .. autofunction:: flaskbb_cli
  44. .. autofunction:: flaskbb_shell_context
  45. FlaskBB Event Hooks
  46. ~~~~~~~~~~~~~~~~~~~
  47. .. autofunction:: flaskbb_event_post_save_before
  48. .. autofunction:: flaskbb_event_post_save_after
  49. .. autofunction:: flaskbb_event_topic_save_before
  50. .. autofunction:: flaskbb_event_topic_save_after
  51. .. autofunction:: flaskbb_event_user_registered
  52. .. autofunction:: flaskbb_authenticate
  53. .. autofunction:: flaskbb_post_authenticate
  54. .. autofunction:: flaskbb_authentication_failed
  55. .. autofunction:: flaskbb_reauth_attempt
  56. .. autofunction:: flaskbb_post_reauth
  57. .. autofunction:: flaskbb_reauth_failed
  58. FlaskBB Form Hooks
  59. ~~~~~~~~~~~~~~~~~~
  60. .. autofunction:: flaskbb_form_new_post_save
  61. .. autofunction:: flaskbb_form_new_post
  62. .. autofunction:: flaskbb_form_new_topic
  63. .. autofunction:: flaskbb_form_new_topic_save
  64. .. autofunction:: flaskbb_form_registration
  65. Template Hooks
  66. --------------
  67. .. note::
  68. Template hooks, which are used in forms, are usually rendered after the
  69. hidden CSRF token field and before an submit field.
  70. .. autofunction:: flaskbb_tpl_navigation_before
  71. .. autofunction:: flaskbb_tpl_navigation_after
  72. .. autofunction:: flaskbb_tpl_user_nav_loggedin_before
  73. .. autofunction:: flaskbb_tpl_user_nav_loggedin_after
  74. .. autofunction:: flaskbb_tpl_form_registration_before
  75. .. autofunction:: flaskbb_tpl_form_registration_after
  76. .. autofunction:: flaskbb_tpl_form_user_details_before
  77. .. autofunction:: flaskbb_tpl_form_user_details_after
  78. .. autofunction:: flaskbb_tpl_form_new_post_before
  79. .. autofunction:: flaskbb_tpl_form_new_post_after
  80. .. autofunction:: flaskbb_tpl_form_new_topic_before
  81. .. autofunction:: flaskbb_tpl_form_new_topic_after
  82. .. autofunction:: flaskbb_tpl_profile_settings_menu
  83. .. autofunction:: flaskbb_tpl_profile_sidebar_stats
  84. .. autofunction:: flaskbb_tpl_post_author_info_before
  85. .. autofunction:: flaskbb_tpl_post_author_info_after
  86. .. autofunction:: flaskbb_tpl_post_content_before
  87. .. autofunction:: flaskbb_tpl_post_content_after
  88. .. autofunction:: flaskbb_tpl_post_menu_before
  89. .. autofunction:: flaskbb_tpl_post_menu_after
  90. .. autofunction:: flaskbb_tpl_topic_controls
  91. .. autofunction:: flaskbb_tpl_admin_settings_menu