-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/27/2011 02:40 PM, Chris Withers wrote:
> Hi All,
> 
> I'm writing a SQLAlchemy SessionExtension based on this pattern:
> 
> http://www.sqlalchemy.org/trac/browser/examples/versioning/history_meta.py?rev=7253:3ef75b251d06#L171
> 
> So, in the listener, I want to record the user that made the change.
> How should I get hold of the currently authenticated user?
> 
> The only way I can think of is calling 
> pyramid.threadlocal.get_current_request inside the before_flush method 
> of the VersionedListener, but having read:
> 
> http://docs.pylonsproject.org/projects/pyramid/1.0/narr/threadlocals.html#why-you-shouldn-t-abuse-thread-locals
> 
> I'm worried that I'm being evil. Am I being evil?
> How else can I get hold of Pyramid's notion of the current user id 
> inside a SessionExtension?

The "approved" way to share request-specific information is to just pass
the request:  in this case, the obvious candidate is to make the request
an attribute of the event.

Reaching around to the thread-local should be seen as a workaround for
not being change the event code, if that happens to be the case.


Tres.
- -- 
===================================================================
Tres Seaver          +1 540-429-0999          tsea...@palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1r1C8ACgkQ+gerLs4ltQ7msACgy4aAvKqy/qLuJN3mLhhn4xZm
nmgAni4Z8Tt6sC1JxBh46dJ0p+GAnuEO
=ClRq
-----END PGP SIGNATURE-----

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to