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: http://djangosnippets.org/snippets/2179/ https://github.com/Proteus-tech/django-request-local W dniu niedziela, 13 maja 2012 09:59:33 UTC+1 użytkownik Alireza napisał: > > 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! > -- 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-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.