add support for getting current request object from within a model
diff --git a/planetstack/core/middleware.py b/planetstack/core/middleware.py
new file mode 100644
index 0000000..1401cd6
--- /dev/null
+++ b/planetstack/core/middleware.py
@@ -0,0 +1,13 @@
+from threading import local
+
+_active = local()
+
+def get_request():
+ if not hasattr(_active, "request"):
+ raise Exception("Please add 'core.middleware.GlobalRequestMiddleware' to /opt/planetstack/planetstack/settings.py:MIDDLEWARE_CLASSES")
+ return _active.request
+
+class GlobalRequestMiddleware(object):
+ def process_view(self, request, view_func, view_args, view_kwargs):
+ _active.request = request
+ return None