Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nounous
re2o
Commits
c82e17d5
Commit
c82e17d5
authored
Jun 22, 2018
by
Maël Kervella
Browse files
Add support for django-debug-toolbar
parent
2f8ea80e
Changes
4
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
c82e17d5
...
...
@@ -71,4 +71,26 @@ OPTIONAL_APPS = (
...
'api',
...
)
\ No newline at end of file
)
```
## 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"]
```
re2o/middleware.py
0 → 100644
View file @
c82e17d5
# 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
)
re2o/settings.py
View file @
c82e17d5
...
...
@@ -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'
...
...
re2o/urls.py
View file @
c82e17d5
...
...
@@ -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'
)),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment