Upgrade orchestra middlewares
Refactor to changes introduced on Django 1.10 https://docs.djangoproject.com/en/2.1/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware
This commit is contained in:
parent
be5e06129a
commit
58be94bde2
|
@ -1,15 +1,15 @@
|
||||||
from threading import local
|
from threading import local
|
||||||
|
|
||||||
from django.contrib.admin.models import LogEntry
|
from django.contrib.admin.models import LogEntry
|
||||||
from django.urls import resolve
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models.signals import pre_delete, post_save, m2m_changed
|
from django.db.models.signals import m2m_changed, post_save, pre_delete
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.http.response import HttpResponseServerError
|
from django.http.response import HttpResponseServerError
|
||||||
|
from django.urls import resolve
|
||||||
|
from django.utils.deprecation import MiddlewareMixin
|
||||||
from orchestra.utils.python import OrderedSet
|
from orchestra.utils.python import OrderedSet
|
||||||
|
|
||||||
from . import manager, Operation
|
from . import Operation, manager
|
||||||
from .helpers import message_user
|
from .helpers import message_user
|
||||||
from .models import BackendLog, BackendOperation
|
from .models import BackendLog, BackendOperation
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ def m2m_collector(sender, *args, **kwargs):
|
||||||
OperationsMiddleware.collect(Operation.SAVE, **kwargs)
|
OperationsMiddleware.collect(Operation.SAVE, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class OperationsMiddleware(object):
|
class OperationsMiddleware(MiddlewareMixin):
|
||||||
"""
|
"""
|
||||||
Stores all the operations derived from save and delete signals and executes them
|
Stores all the operations derived from save and delete signals and executes them
|
||||||
at the end of the request/response cycle
|
at the end of the request/response cycle
|
||||||
|
|
|
@ -2,7 +2,7 @@ from threading import currentThread
|
||||||
|
|
||||||
from django.core.cache.backends.dummy import DummyCache
|
from django.core.cache.backends.dummy import DummyCache
|
||||||
from django.core.cache.backends.locmem import LocMemCache
|
from django.core.cache.backends.locmem import LocMemCache
|
||||||
|
from django.utils.deprecation import MiddlewareMixin
|
||||||
|
|
||||||
_request_cache = {}
|
_request_cache = {}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ def get_request_cache():
|
||||||
return DummyCache('dummy', {})
|
return DummyCache('dummy', {})
|
||||||
|
|
||||||
|
|
||||||
class RequestCacheMiddleware(object):
|
class RequestCacheMiddleware(MiddlewareMixin):
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
current_thread = currentThread()
|
current_thread = currentThread()
|
||||||
cache = _request_cache.get(current_thread, RequestCache())
|
cache = _request_cache.get(current_thread, RequestCache())
|
||||||
|
|
Loading…
Reference in a new issue