Created
July 3, 2014 18:22
-
-
Save nick-merrill/a18f6cba8bd0215e1847 to your computer and use it in GitHub Desktop.
Django: Adds user information to the request's META dictionary, which helps when processing logs via mail_admins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExceptionUserInfoMiddleware(object): | |
def process_exception(self, request, exception): | |
try: | |
user = request.user | |
if user.is_authenticated(): | |
request.META['USER_ID'] = str(user.id) | |
request.META['USER_NAME'] = str("%s %s" % (user.first_name, user.last_name)) | |
request.META['USER_EMAIL'] = str(user.email) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment