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"): |
Scott Baker | 76a840e | 2015-02-11 21:38:09 -0800 | [diff] [blame] | 7 | raise Exception("Please add 'core.middleware.GlobalRequestMiddleware' to <XOS_DIR>/xos.settings.py:MIDDLEWARE_CLASSES") |
Scott Baker | 6810db2 | 2014-08-26 17:40:36 -0700 | [diff] [blame] | 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 |