Essentially, I'm just trying to make a simple email alert system. If anyone creates, modifies or deletes an entry in the admin back end, I'll receive an email as to which user did what to which model. I already figured out how to detect the 3 user actions mentioned above in the models.py as well as how to send email templates. The issue is that I need to the current user information to insert into that email template. And like I mentioned before, this is an admin back end, meaning I'm not touching the views.py at all.
If there are any other ways to accomplish this, I'm all ears!
Thanks
--
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...@googlegroups.com.
To post to this group, send email to django...@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.
I've repeatedly asked about this over the past couple of years and
there seems to be no "right" answer." This, to me, is the biggest flaw
in Django.
The official (and useless) answer is that you must pass "user" in
everywhere you save anything. This is stupid, obviously, because you
can not rewrite every third-party app to support this (among other
reasons).
There was a good tutorial for using threadlocals on the
official Django wiki but someone deleted it in a fit of spite a few
years ago.
On 15/03/2013 10:31am, Russell Keith-Magee wrote:
<mailto:sh...@milochik.com>> wrote:
I've repeatedly asked about this over the past couple of years and
there seems to be no "right" answer." This, to me, is the biggest flaw
in Django.
There's definitely a right answer.
Russell
What is the right way to design a system whereby on every save for every model the updated_by column is changed to the user.id of the logged-in user? This has to happen whether updates are done via views or the Django-Admin.
And I'm saying anonymous users can't update at all.
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/561482b8-a4bf-44fd-9c7d-ef2bbec54726%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Collin and Russell (and anyone else),
Do you have any opinion on this?
- https://bitbucket.org/aptivate/django-current-user
It was offered in an earlier post:
- https://groups.google.com/d/msg/django-users/y7aIbN2_CsA/GtmrSjG1nq8J
as a solution to exactly this problem.
Makes the current user available to the save() method of all
models.
I read the code and it looks good, but I don't know the details
of Apache/WSGI/Django/Python multi-threading well enough
to know if it is thread safe.
Thoughts?
import threading
store = threading.local()
class Middleware:
def process_request(self, request):
store.request = request
def process_response(self, request, response):
del store.request
return response
import inspect
for line in inspect.stack():
if 'request' in line[0].f_locals:
request = line[0].f_locals['request']
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.
On 12/14/14 2:13 PM, Collin Anderson wrote: