Middleware¶
Shortcuts when using django-reversion in views.
reversion.middleware.RevisionMiddleware¶
Wrap every request in a revision block.
The request user will also be added to the revision metadata.
To enable RevisionMiddleware, add 'reversion.middleware.RevisionMiddleware' to your MIDDLEWARE_CLASSES setting. For Django >= 1.10, add it to your MIDDLEWARE setting.
Warning
This will wrap every request that meets the specified criterion in a database transaction. For best performance, consider marking individual views instead.
RevisionMiddleware.manage_manually = False
IfTrue, versions will not be saved when a model’ssave()method is called. This allows version control to be switched off for a given revision block.
RevisionMiddleware.using = None
The database to save the revision data. The revision block will be wrapped in a transaction using this database. IfNone, the default database for reversion.models.Revision will be used.
RevisionMiddleware.atomic = True
IfTrue, the revision block will be wrapped in atransaction.atomic().
RevisionMiddleware.request_creates_revision(request)
By default, any request that isn’t
GET,HEADorOPTIONSwill be wrapped in a revision block. Override this method if you need to apply a custom rule.For example:
from reversion.middleware import RevisionMiddleware class BypassRevisionMiddleware(RevisionMiddleware): def request_creates_revision(self, request): # Bypass the revision according to some header silent = request.META.get("HTTP_X_NOREVISION", "false") return super().request_creates_revision(request) and \ silent != "true"