getting request.user from a signal

1,185 views
Skip to first unread message

Shawn Milochik

unread,
Mar 11, 2010, 11:35:00 AM3/11/10
to django...@googlegroups.com
Yes, this is essentially the same topic that was discussed here: http://groups.google.com/group/django-users/browse_thread/thread/44ced967d9da3500
However, there has not yet been an answer, and I think this particular
(and probably common) use-case renders the "write a function that
accepts a user argument" untenable.

Very simple requirement:
Every time a post_save signal fires, I want to store the values of the
model instance, along with the timestamp and the user who made the
change.

Considering that this also applies to models from pluggable and
otherwise reusable applications, it is not even sane to go and modify
all the save() methods of the models and every view that uses those
models. I'm looking for a way to store this information for auditing
purposes.

Is this possible in Django? If the answer is 'no,' then it's 'no.' But
so far I haven't heard that this is impossible, just that attempting
it is somehow morally wrong.

Shawn

Andy McKay

unread,
Mar 11, 2010, 4:58:13 PM3/11/10
to django...@googlegroups.com
> Yes, this is essentially the same topic that was discussed here: http://groups.google.com/group/django-users/browse_thread/thread/44ced967d9da3500
> However, there has not yet been an answer, and I think this particular (and probably common) use-case renders the "write a function that accepts a user argument" untenable.

No, but there's lots of other solutions. Marty Alchin solves this nicely with CurrentUserMiddleware:

http://bit.ly/9lIxsM

I've been wanting to make this into a reusable app for a long time, but the license on that code snippet is unclear.
--
Andy McKay, @clearwind

Reply all
Reply to author
Forward
0 new messages