Scott Baker | 6810db2 | 2014-08-26 17:40:36 -0700 | [diff] [blame] | 1 | from threading import local |
2 | |||||
3 | _active = local() | ||||
4 | |||||
5 | def get_request(): | ||||
6 | if not hasattr(_active, "request"): | ||||
7 | raise Exception("Please add 'core.middleware.GlobalRequestMiddleware' to /opt/planetstack/planetstack/settings.py:MIDDLEWARE_CLASSES") | ||||
8 | return _active.request | ||||
9 | |||||
10 | class GlobalRequestMiddleware(object): | ||||
11 | def process_view(self, request, view_func, view_args, view_kwargs): | ||||
12 | _active.request = request | ||||
13 | return None |