- September 7, 2009
- admin user auth debugging 500
- 4 (after 4 ratings)
Based loosely on Eric's middleware, this middleware will show the technical 500 page (which you'd get if DEBUG == True) to any user who is (1) superuser and (2) a member of the settings.TECHNICAL_500_GROUP_NAME group. (If no setting exists, 'Technical Errors' is the presumed group name.
I agreed with the comments that caching should be unnecessary given the (presumptive) edge case of exception + superuser. Assuming you don't have tons of superusers, this code is a good bit simpler.
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 6 years, 9 months ago
- Restrict Flatpage To Group by nikolaj 7 years, 1 month ago
- Restricting admin fieldsets for non-superusers by phretor 5 years, 9 months ago
- Active Directory Authentication Backend (with User object updating) by mroose 3 years, 6 months ago
- Message exception by marinho 6 years, 7 months ago