Skip to content

Commit

Permalink
Merge pull request #2719 from freelawproject/fix-internal-ips-list
Browse files Browse the repository at this point in the history
fix(settings): Add logic to get the list of INTERNAL_IPS
  • Loading branch information
ERosendo authored May 3, 2023
2 parents b769d41 + 7b32993 commit f242381
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 5 deletions.
10 changes: 10 additions & 0 deletions cl/assets/static-global/js/fix-toolbar-for-htmx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if (typeof window.htmx !== "undefined") {
htmx.on("htmx:afterSettle", function(detail) {
if (
typeof window.djdt !== "undefined"
&& detail.target instanceof HTMLBodyElement
) {
djdt.show_toolbar();
}
});
}
1 change: 1 addition & 0 deletions cl/settings/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@

if DEVELOPMENT:
INSTALLED_APPS.append("django_extensions")
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")


################
Expand Down
12 changes: 9 additions & 3 deletions cl/settings/project/security.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import socket

import environ

from ..django import DATABASES, TESTING
from ..django import DATABASES, INSTALLED_APPS, TESTING

env = environ.FileAwareEnv()
DEVELOPMENT = env.bool("DEVELOPMENT", default=True)
Expand Down Expand Up @@ -28,8 +30,12 @@
CSRF_COOKIE_SECURE = False
SESSION_COOKIE_DOMAIN = None
# For debug_toolbar
# INSTALLED_APPS.append('debug_toolbar')
INTERNAL_IPS = ("127.0.0.1",)
INSTALLED_APPS.append("debug_toolbar")

hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [".".join(ip.split(".")[:-1] + ["1"]) for ip in ips] + [
"127.0.0.1"
]

if TESTING:
db = DATABASES["default"]
Expand Down
9 changes: 8 additions & 1 deletion cl/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@
"removal/",
RedirectView.as_view(url="/terms/#removal", permanent=True),
),
] + static("/", document_root=settings.MEDIA_ROOT)
]

if settings.DEVELOPMENT:
urlpatterns.append(
path("__debug__/", include("debug_toolbar.urls")),
)

urlpatterns += static("/", document_root=settings.MEDIA_ROOT) # type: ignore
1 change: 1 addition & 0 deletions cl/users/templates/profile/recap_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{% if DEBUG %}
<script src="{% static "js/jquery.bootstrap-growl.js" %}"></script>
<script src="{% static "js/htmx.js" %}"></script>
<script src="{% static "js/fix-toolbar-for-htmx.js" %}"></script>
<link href="{% static "css/bootstrap4-toggle.css" %}" rel="stylesheet">
{% else %}
<script src="{% static "js/jquery.bootstrap-growl.min.js" %}"></script>
Expand Down
1 change: 1 addition & 0 deletions cl/users/templates/profile/webhooks_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script src="{% static "js/loading-states.js" %}" defer></script>
{% if DEBUG %}
<script src="{% static "js/htmx.js" %}"></script>
<script src="{% static "js/fix-toolbar-for-htmx.js" %}"></script>
{% else %}
<script src="{% static "js/htmx.min.js" %}"></script>
{% endif %}
Expand Down
18 changes: 17 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ djangorestframework-stubs = "^3.14.0"
black = "^23.3.0"
types-simplejson = "^3.19.0.0"
lxml-stubs = "^0.4.0"
django-debug-toolbar = "^4.0.0"

[tool.black]
include = '''
Expand Down

0 comments on commit f242381

Please sign in to comment.