1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from django.conf import settings
from django.views.debug import technical_500_response
import sys
EX_GROUP_NAME = getattr(settings, 'TECHNICAL_500_GROUP_NAME', 'Technical Errors')
class UserBasedExceptionMiddleware(object):
def process_exception(self, request, exception):
exc_info = sys.exc_info()
user = request.user
if not user.is_superuser:
return None
if user.groups.filter(name=EX_GROUP_NAME):
return technical_500_response(request, *exc_info)
return None
|
More like this
- Super User Conditional Page Exception Reporting by zbyte64 3 years, 9 months ago
- Debug middleware for displaying sql queries and template loading info when ?debug=true by SEJeff 1 year, 1 month ago
- More information about users and groups in user admin by ramusus 2 years, 9 months ago
- Restrict Flatpage To Group by nikolaj 4 years, 1 month ago
- More information about users and groups in user admin by buriy 3 years, 10 months ago
Comments
you better use bool(user.groups.filter(name=EX_GROUP_NAME)), count is unnecessary here ( nonzero is overloaded for querysets) and count is slow on transactional storages.
#
or just "if user.groups.filter(name=EX_GROUP_NAME)" :)
#
".count()" is faster but I agree that it can be tested directly in the "if" ;)
#
I edited it to do the test in the "if" directly. Slightly less obvious code to me, now, but shrug.
#
Nice. But i think the old idea is nicer: http://ericholscher.com/blog/2008/nov/15/debugging-django-production-environments/
#