mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Add support for django-debug-toolbar
This commit is contained in:
parent
2f8ea80e7f
commit
c82e17d5fd
4 changed files with 82 additions and 1 deletions
24
CHANGELOG.md
24
CHANGELOG.md
|
@ -71,4 +71,26 @@ OPTIONAL_APPS = (
|
|||
...
|
||||
'api',
|
||||
...
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
||||
## MR 177: Add django-debug-toolbar support
|
||||
|
||||
Add the possibility to enable `django-debug-toolbar` in debug mode. First install the APT package:
|
||||
```
|
||||
apt install pyhton3-django-debug-toolbar
|
||||
```
|
||||
And then activate it for Re2o by adding the app to the `OPTIONAL_APPS` in `re2o/settings_local.py`:
|
||||
```python
|
||||
OPTIONAL_APPS = (
|
||||
# ...
|
||||
'debug_toolbar',
|
||||
# ...
|
||||
)
|
||||
```
|
||||
If you to restrict the IP which can see the debug, use the `INTERNAL_IPS` options in `re2o/settings_local.py`:
|
||||
```
|
||||
INTERNAL_IPS = ["10.0.0.1", "10.0.0.2"]
|
||||
```
|
||||
|
|
43
re2o/middleware.py
Normal file
43
re2o/middleware.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
||||
# se veut agnostique au réseau considéré, de manière à être installable en
|
||||
# quelques clics.
|
||||
#
|
||||
# Copyright © 2018 Maël Kervella
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
"""Defines the middlewares used in all apps of re2o.
|
||||
"""
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def show_debug_toolbar(request):
|
||||
"""Middleware to determine wether to show the toolbar.
|
||||
|
||||
Compared to `django-debug-toolbar`'s default, add the possibility to allow
|
||||
any IP to see the debug panel by not setting the `INTERNAL_IPS` options
|
||||
|
||||
Args:
|
||||
requests: The request object that must be checked.
|
||||
|
||||
Returns:
|
||||
The boolean indicating if the debug toolbar should be shown.
|
||||
"""
|
||||
if hasattr(settings, 'INTERNAL_IPS') and settings.INTERNAL_IPS and \
|
||||
request.META.get('REMOTE_ADDR', None) not in settings.INTERNAL_IPS:
|
||||
return False
|
||||
|
||||
return bool(settings.DEBUG)
|
|
@ -94,6 +94,16 @@ MIDDLEWARE_CLASSES = (
|
|||
'django.middleware.security.SecurityMiddleware',
|
||||
'reversion.middleware.RevisionMiddleware',
|
||||
)
|
||||
# Include debug_toolbar middleware if activated
|
||||
if 'debug_toolbar' in INSTALLED_APPS:
|
||||
# Include this middleware at the beggining
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
) + MIDDLEWARE_CLASSES
|
||||
# Change the default show_toolbar middleware
|
||||
DEBUG_TOOLBAR_CONFIG = {
|
||||
'SHOW_TOOLBAR_CALLBACK': 're2o.middleware.show_debug_toolbar'
|
||||
}
|
||||
|
||||
# The root url module to define the project URLs
|
||||
ROOT_URLCONF = 're2o.urls'
|
||||
|
|
|
@ -72,6 +72,12 @@ urlpatterns = [
|
|||
include('preferences.urls', namespace='preferences')
|
||||
),
|
||||
]
|
||||
# Add debug_toolbar URLs if activated
|
||||
if 'debug_toolbar' in settings.INSTALLED_APPS:
|
||||
import debug_toolbar
|
||||
urlpatterns += [
|
||||
url(r'^__debug__/', include(debug_toolbar.urls)),
|
||||
]
|
||||
if 'api' in settings.INSTALLED_APPS:
|
||||
urlpatterns += [
|
||||
url(r'^api/', include('api.urls', namespace='api')),
|
||||
|
|
Loading…
Reference in a new issue