From 4694885f6278d76e2a54a7daf248678dd7ee779d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Schl=C3=B6gl?= Date: Tue, 10 Dec 2024 16:46:40 +0100 Subject: [PATCH] docs(history): add section on middleware for user tracking --- docs/source/features.rst | 19 +++++++++++++++++++ sample_project/settings.py | 1 + 2 files changed, 20 insertions(+) diff --git a/docs/source/features.rst b/docs/source/features.rst index 5c36e9993..6e2103aa0 100644 --- a/docs/source/features.rst +++ b/docs/source/features.rst @@ -11,6 +11,25 @@ The :py:mod:`apis_core.history` module provides versioning for APIS. It is based on the `django-simple-history`_ package. +Track changes by users +^^^^^^^^^^^^^^^^^^^^^^ + +To record the user who made a change, the `django-simple-history` module +used by APIS provides a middleware that sets the `history_user` attribute of +the request object to the current user. It then saves this information to the +`history_user` attribute of the historical record. +To activate the middleware, add `simple_history.middleware.HistoryRequestMiddleware` +to your `MIDDLEWARE` setting: + +.. code-block:: python + + MIDDLEWARE = [ + ... + 'apis_core.history.middleware.HistoryRequestMiddleware', + ... + ] + + VersionMixin ^^^^^^^^^^^^ diff --git a/sample_project/settings.py b/sample_project/settings.py index b5c316620..d6a03d7bb 100644 --- a/sample_project/settings.py +++ b/sample_project/settings.py @@ -71,6 +71,7 @@ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "crum.CurrentRequestUserMiddleware", + "simple_history.middleware.HistoryRequestMiddleware", ] # ROOT_URLCONF = "apis_core.urls"