Get request.user outside of [admin|models|views].py

208 views
Skip to first unread message

Alireza Savand

unread,
May 13, 2012, 4:59:33 AM5/13/12
to django...@googlegroups.com
Hi

Let me explain it. i developing and app to trace the models activity, hmmm. actualy it's reversioning app for other models. As a reversioning model shoulda store user_id. What i'm trying to do is to connect those models post_save signal to create a reversion on each changes. But i don't want to explicity [expose|pass] the user to it
And those model that shoulda be reversioning, don't have any ForeignKey to the auth.User.
By The dummy way it can be done in the save_model at admin.py to pass the request.user to it. but then the program will stuck in the admin.py area and it's not a encapsulated way!
You know it's all about who make this change.
So all stuff shoulda be handle it in the app itself, i mean the reversioning app ;)
At the django-reversion they did something similar, that i couldn't get it exactly. As AeroNotix says at the #django 
see, this is the annoying part about using the auth module
Which i'm agree with it.

But the topic is not about annoying part about auth module, it's about Access to request.user.
And a little bit for tiny solution is can we somehow make request.user widely? 

Thank you! 

Rafał Stożek

unread,
May 13, 2012, 10:27:39 AM5/13/12
to django...@googlegroups.com
It is possible using simple middleware and http://docs.python.org/library/threading.html#threading.local class. But note that code doesn't have to always be called from HTTP - it means that you must handle situation where user is not known.

Examples:

Alireza Savand

unread,
May 13, 2012, 10:33:43 AM5/13/12
to django...@googlegroups.com

Also i found https://github.com/seveas/django-echelon very usefull
Specially CurrentUserFiled
For the information, use shoulda be always authenticated so it's not a case here!
Thank you

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/rKMFkoIPC_UJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--

Reply all
Reply to author
Forward
0 new messages