Skip to content

Commit da61d38

Browse files
committed
[Core] Add a configuration file.
Give the possiblity to configure if the user must be staff. Fixes: #17
1 parent ba3a892 commit da61d38

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

django_cprofile_middleware/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
"""A module to manage the configuration."""
3+
from django.conf import settings
4+
5+
CPROFILE_MIDDLEWARE_REQUIRE_STAFF = getattr(
6+
settings, 'CPROFILE_MIDDLEWARE_REQUIRE_STAFF', True)

django_cprofile_middleware/middleware.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from django.conf import settings
1414
from django.http import HttpResponse
1515

16+
from django_cprofile_middleware.conf import CPROFILE_MIDDLEWARE_REQUIRE_STAFF
17+
1618
if django.VERSION >= (1, 10):
1719
from django.utils.deprecation import MiddlewareMixin
1820
else:
@@ -41,8 +43,13 @@ class ProfilerMiddleware(MiddlewareMixin):
4143
http://www.slideshare.net/zeeg/django-con-high-performance-django-presentation.
4244
"""
4345
def can(self, request):
44-
return settings.DEBUG and 'prof' in request.GET and \
45-
request.user is not None and request.user.is_staff
46+
if request.user is None:
47+
return False
48+
49+
prof = request.GET.get('prof', None)
50+
51+
return settings.DEBUG and prof \
52+
and request.user.is_staff or not CPROFILE_MIDDLEWARE_REQUIRE_STAFF
4653

4754
def process_view(self, request, callback, callback_args, callback_kwargs):
4855
if self.can(request):

0 commit comments

Comments
 (0)