audit_log.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. .. _audit_log:
  2. Audit log
  3. =========
  4. Wagtail provides a mechanism to log actions performed on its objects. Common activities such as page creation, update, deletion,
  5. locking and unlocking, revision scheduling and privacy changes are automatically logged at the model level.
  6. The Wagtail admin uses the action log entries to provide a site-wide and page specific history of changes. It uses a
  7. registry of 'actions' that provide additional context for the logged action.
  8. The audit log-driven Page history replaces the revisions list page, but provide a filter for revision-specific entries.
  9. .. note:: The audit log does not replace revisions
  10. To provide additional ``Page`` logging for your site or package, invoke the :meth:`~PageLogEntryManger.log_action` manager method
  11. via ``PageLogEntry.objects.log_action(object_instance, action)`` and register a ``register_log_actions`` hook to
  12. describe your action (see :ref:`register_log_actions`).
  13. .. note:: When adding logging, you need to log the action or actions that happen to the ``Page``. For example, if the
  14. user creates and publishes, there should be a "create" entry and a "publish" entry. Or, if the user copies a
  15. published page and chooses to keep it published, there should be a "copy" and a "publish" entry for new page.
  16. You can provide additional metadata by passing additional parameters:
  17. - ``user`` - a user object.
  18. - ``data`` - a data dictionary, stored as JSON
  19. - ``title`` - by default, Wagtail will attempt to use ``get_admin_display_title`` or the string representation of the passed object.
  20. .. code-block:: python
  21. # mypackage/views.py
  22. from wagtail.core.models import PageLogEntry
  23. def copy_for_translation(page):
  24. # ...
  25. page.copy(log_action='mypackage.copy_for_translation')
  26. def my_method(request, page):
  27. # ..
  28. # Manually log an action
  29. data = {
  30. 'make': {'it': 'so'}
  31. }
  32. PageLogEntry.objects.log_action(
  33. instance=page, action='mypackage.custom_action', user=request.user, data=data
  34. )
  35. To log actions for your non-page model, you can create a class that inherits from ``BaseLogEntry`` with the appropriate
  36. linking.
  37. Log actions provided by Wagtail
  38. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. =================================== =====
  40. Action Notes
  41. =================================== =====
  42. ``wagtail.create`` The page was created
  43. ``wagtail.edit`` A draft was saved
  44. ``wagtail.delete`` The page was deleted. Will only surface in the Site History for administrators
  45. ``wagtail.publish`` The page was published
  46. ``wagtail.publish.schedule`` Draft is scheduled for publishing
  47. ``wagtail.publish.scheduled`` Draft published via ``publish_scheduled_pages`` management command
  48. ``wagtail.schedule.cancel`` Draft scheduled for publishing cancelled via "Cancel scheduled publish"
  49. ``wagtail.unpublish`` The page was unpublished
  50. ``wagtail.unpublish.scheduled`` Page unpublished via ``publish_scheduled_pages`` management command
  51. ``wagtail.lock`` Page was locked
  52. ``wagtail.unlock`` Page was unlocked
  53. ``wagtail.moderation.approve`` The revision was approved for moderation
  54. ``wagtail.moderation.reject`` The revision was rejected
  55. ``wagtail.rename`` A page was renamed
  56. ``wagtail.revert`` The page was reverted to a previous draft
  57. ``wagtail.copy`` The page was copied to a new location
  58. ``wagtail.move`` The page was moved to a new location
  59. ``wagtail.view_restriction.create`` The page was restricted
  60. ``wagtail.view_restriction.edit`` The page restrictions were updated
  61. ``wagtail.view_restriction.delete`` The page restrictions were removed
  62. ``wagtail.workflow.start`` The page was submitted for moderation in a Workflow
  63. ``wagtail.workflow.approve`` The draft was approved at a Workflow Task
  64. ``wagtail.workflow.reject`` The draft was rejected, and changes requested at a Workflow Task
  65. ``wagtail.workflow.resume`` The draft was resubmitted to the workflow
  66. ``wagtail.workflow.cancel`` The workflow was cancelled
  67. =================================== =====