Skip to content

Commit 1302bb2

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 1302bb2

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
@@ -18,6 +18,8 @@
1818
else:
1919
from django_cprofile_middleware.utils import MiddlewareMixin
2020

21+
from django_cprofile_middleware.conf import CPROFILE_MIDDLEWARE_REQUIRE_STAFF
22+
2123

2224
class ProfilerMiddleware(MiddlewareMixin):
2325
"""
@@ -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)