Created
December 10, 2013 08:38
-
-
Save bitemyapp/7887449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_request(): | |
""" | |
blindly walks up the stack looking for | |
request.user | |
""" | |
for i in itertools.count(): | |
try: | |
frame = sys._getframe(i) | |
except ValueError: | |
frame = None | |
if not frame: return None | |
if "request" in frame.f_locals: | |
request = frame.f_locals['request'] | |
if not isinstance(request, HttpRequest) or not hasattr(request, "user"): | |
# wrong signature... keep looking | |
continue | |
return request |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment