Hi,

I am developing a Django application which will be accessed by it's users 
both via HTTP and through the Python shell. All of my models have a 
"touch_user" and "create_user" attribute, containing usernames in plain 
text. This is primarily used for logging purposes, nothing critical. My 
idea was that whenever a model's save method is being invoked that the 
"touch_user" attribute is set to the current username.

In the Python shell this is already working with getpass.getuser(). As you 
might have guessed already I also want to do this when the models are saved 
through the web, both in Django's admin as well as in my custom views. 
Since I do not want to add a custom save()-Method (I am using the 
pre_save() signal for this) I needed some way to access the username in the 
backend, without a HTTP request instance. So I created a custom middleware 
which stores the REMOTE_USER in os.environ like this:

def process_request(self, request):
    if request.META.has_key('REMOTE_USER'):
        os.environ['REMOTE_USER'] = request.META['REMOTE_USER']

Now while this approach works for me I'd like to know if there is a better 
way of doing this? Is this method even safe with Apache and mod_wsgi, or 
would threading.local be a better approach here? I am not using os.environ 
for authorization or anything mission-critical, but it'd still be good to 
know if this can go wrong.


Regards,
Frederik 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to