Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
django-simple-history/simple_history/middleware.py /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20 lines (14 sloc)
660 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.utils.deprecation import MiddlewareMixin | |
| from .models import HistoricalRecords | |
| class HistoryRequestMiddleware(MiddlewareMixin): | |
| """Expose request to HistoricalRecords. | |
| This middleware sets request as a local context/thread variable, making it | |
| available to the model-level utilities to allow tracking of the authenticated user | |
| making a change. | |
| """ | |
| def process_request(self, request): | |
| HistoricalRecords.context.request = request | |
| def process_response(self, request, response): | |
| if hasattr(HistoricalRecords.context, "request"): | |
| del HistoricalRecords.context.request | |
| return response |