Commit 437b249d by Calen Pennington

Use django_crum to access the current request in request_cache

parent 93970f34
...@@ -312,6 +312,7 @@ simplefilter('ignore') ...@@ -312,6 +312,7 @@ simplefilter('ignore')
################################# Middleware ################################### ################################# Middleware ###################################
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'crum.CurrentRequestUserMiddleware',
'request_cache.middleware.RequestCache', 'request_cache.middleware.RequestCache',
'header_control.middleware.HeaderControlMiddleware', 'header_control.middleware.HeaderControlMiddleware',
'django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.cache.UpdateCacheMiddleware',
...@@ -332,7 +333,6 @@ MIDDLEWARE_CLASSES = ( ...@@ -332,7 +333,6 @@ MIDDLEWARE_CLASSES = (
'student.middleware.UserStandingMiddleware', 'student.middleware.UserStandingMiddleware',
'contentserver.middleware.StaticContentServer', 'contentserver.middleware.StaticContentServer',
'crum.CurrentRequestUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'track.middleware.TrackMiddleware', 'track.middleware.TrackMiddleware',
......
"""
An implementation of a RequestCache. This cache is reset at the beginning
and end of every request.
"""
import crum
import threading import threading
...@@ -8,7 +14,6 @@ class _RequestCache(threading.local): ...@@ -8,7 +14,6 @@ class _RequestCache(threading.local):
def __init__(self): def __init__(self):
super(_RequestCache, self).__init__() super(_RequestCache, self).__init__()
self.data = {} self.data = {}
self.request = None
REQUEST_CACHE = _RequestCache() REQUEST_CACHE = _RequestCache()
...@@ -30,7 +35,7 @@ class RequestCache(object): ...@@ -30,7 +35,7 @@ class RequestCache(object):
""" """
This method is deprecated. Please use :func:`request_cache.get_request`. This method is deprecated. Please use :func:`request_cache.get_request`.
""" """
return REQUEST_CACHE.request return crum.get_current_request()
@classmethod @classmethod
def clear_request_cache(cls): def clear_request_cache(cls):
...@@ -38,11 +43,9 @@ class RequestCache(object): ...@@ -38,11 +43,9 @@ class RequestCache(object):
Empty the request cache. Empty the request cache.
""" """
REQUEST_CACHE.data = {} REQUEST_CACHE.data = {}
REQUEST_CACHE.request = None
def process_request(self, request): def process_request(self, request):
self.clear_request_cache() self.clear_request_cache()
REQUEST_CACHE.request = request
return None return None
def process_response(self, request, response): def process_response(self, request, response):
......
...@@ -1087,7 +1087,10 @@ simplefilter('ignore') ...@@ -1087,7 +1087,10 @@ simplefilter('ignore')
################################# Middleware ################################### ################################# Middleware ###################################
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'crum.CurrentRequestUserMiddleware',
'request_cache.middleware.RequestCache', 'request_cache.middleware.RequestCache',
'mobile_api.middleware.AppVersionUpgrade', 'mobile_api.middleware.AppVersionUpgrade',
'header_control.middleware.HeaderControlMiddleware', 'header_control.middleware.HeaderControlMiddleware',
'microsite_configuration.middleware.MicrositeMiddleware', 'microsite_configuration.middleware.MicrositeMiddleware',
...@@ -1111,7 +1114,6 @@ MIDDLEWARE_CLASSES = ( ...@@ -1111,7 +1114,6 @@ MIDDLEWARE_CLASSES = (
'student.middleware.UserStandingMiddleware', 'student.middleware.UserStandingMiddleware',
'contentserver.middleware.StaticContentServer', 'contentserver.middleware.StaticContentServer',
'crum.CurrentRequestUserMiddleware',
# Adds user tags to tracking events # Adds user tags to tracking events
# Must go before TrackMiddleware, to get the context set up # Must go before TrackMiddleware, to get the context set up
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment