Skip to content

Commit

Permalink
[Core] Add a configuration file.
Browse files Browse the repository at this point in the history
Give the possiblity to configure if the user must be staff.

Fixes: #17
  • Loading branch information
hobbestigrou committed Apr 3, 2018
1 parent ba3a892 commit 62ebe9b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions django_cprofile_middleware/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ class ProfilerMiddleware(MiddlewareMixin):
http://www.slideshare.net/zeeg/django-con-high-performance-django-presentation.
"""
def can(self, request):
return settings.DEBUG and 'prof' in request.GET and \
request.user is not None and request.user.is_staff
if request.user is None:
return False

prof = request.GET.get('prof', None)
CPROFILE_MIDDLEWARE_REQUIRE_STAFF = getattr(
settings, 'CPROFILE_MIDDLEWARE_REQUIRE_STAFF', True)

return settings.DEBUG and prof \
and request.user.is_staff or not CPROFILE_MIDDLEWARE_REQUIRE_STAFF

def process_view(self, request, callback, callback_args, callback_kwargs):
if self.can(request):
Expand Down

0 comments on commit 62ebe9b

Please sign in to comment.