I have a global pre_save
signal where I need to get the current logged in user i.e request.user
.
I have tried the following which seems to work however, it looks like a bad idea...
@receiver(pre_save)
def my_handler(sender, **kwargs):
import inspect
for frame_record in inspect.stack():
if frame_record[3] == 'get_response':
request = frame_record[0].f_locals['request']
break
else:
request = None
print(request.user) <--- correct user is given
Are there any potential issues with above? Is there a better way to achieve this?
Using Python 3.4 and Django 1.8.4