From 7cfd68f30607c36924db9dfe481be121448c9b3c Mon Sep 17 00:00:00 2001 From: Injoon Hwang Date: Wed, 9 Aug 2023 14:12:58 +0000 Subject: [PATCH 1/3] fix(debug): show toolbar always --- ara/settings/dev/__init__.py | 15 ++++++++++++++- ara/settings/django.py | 7 ------- ara/urls.py | 5 +---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ara/settings/dev/__init__.py b/ara/settings/dev/__init__.py index c5ce02f2..232ed794 100644 --- a/ara/settings/dev/__init__.py +++ b/ara/settings/dev/__init__.py @@ -1,3 +1,4 @@ +import socket from datetime import datetime, timezone from ara.settings import INSTALLED_APPS, LOGGING, MIDDLEWARE @@ -12,7 +13,7 @@ "http://localhost", ] -CORS_ORIGIN_ALLOW_ALL = True +CORS_ALLOW_ALL_ORIGINS = True SSO_IS_BETA = False @@ -29,6 +30,18 @@ "debug_toolbar_force.middleware.ForceDebugToolbarMiddleware", ] +# https://django-debug-toolbar.readthedocs.io/ + +_, _, ips = socket.gethostbyname_ex(socket.gethostname()) +INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + [ + "127.0.0.1", + "10.0.2.2", +] + +DEBUG_TOOLBAR_CONFIG = { + "SHOW_TOOLBAR_CALLBACK": lambda _: True, +} + REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"] = ( "rest_framework.authentication.BasicAuthentication", "ara.authentication.CsrfExemptSessionAuthentication", diff --git a/ara/settings/django.py b/ara/settings/django.py index d6772dc3..49409645 100644 --- a/ara/settings/django.py +++ b/ara/settings/django.py @@ -118,15 +118,8 @@ STATIC_URL = "/static/" - -# https://django-debug-toolbar.readthedocs.io/ - INTERNAL_IPS = ("127.0.0.1",) -if env("DJANGO_ENV") == "development": - INTERNAL_IPS = type(str("c"), (), {"__contains__": lambda *a: True})() - - SESSION_ENGINE = "django.contrib.sessions.backends.db" SESSION_COOKIE_HTTPONLY = True SESSION_COOKIE_SECURE = True diff --git a/ara/urls.py b/ara/urls.py index ea27cf64..50e0990a 100644 --- a/ara/urls.py +++ b/ara/urls.py @@ -39,10 +39,7 @@ ), ] -# installed apps (test environment) if settings.DEBUG: - import debug_toolbar - urlpatterns += [ - path("__debug__/", include(debug_toolbar.urls)), + path("api/__debug__/", include("debug_toolbar.urls")), ] From b0bf91c8af1f28b7dae06ebc8a50132eb06c485c Mon Sep 17 00:00:00 2001 From: Injoon Hwang Date: Thu, 10 Aug 2023 07:09:52 +0000 Subject: [PATCH 2/3] fix(debug): hide toolbar when testing --- ara/settings/test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ara/settings/test.py b/ara/settings/test.py index ff688063..31310c31 100644 --- a/ara/settings/test.py +++ b/ara/settings/test.py @@ -28,3 +28,7 @@ CELERY_TASK_ALWAYS_EAGER = True ELASTICSEARCH_INDEX_NAME = "articles_test" + +DEBUG_TOOLBAR_CONFIG = { + "SHOW_TOOLBAR_CALLBACK": lambda _: False, +} From 9a4f3f41d3b161efa368d5c9c87edb5c1b2be82c Mon Sep 17 00:00:00 2001 From: Injoon Hwang Date: Thu, 10 Aug 2023 08:09:49 +0000 Subject: [PATCH 3/3] fix(article): add board group to select_related --- apps/core/views/viewsets/article.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/core/views/viewsets/article.py b/apps/core/views/viewsets/article.py index a5a0bd59..bf6067e9 100644 --- a/apps/core/views/viewsets/article.py +++ b/apps/core/views/viewsets/article.py @@ -108,6 +108,7 @@ def filter_queryset(self, queryset): "created_by__profile", "parent_topic", "parent_board", + "parent_board__group", ).prefetch_related( ArticleReadLog.prefetch_my_article_read_log(self.request.user), ) @@ -119,6 +120,7 @@ def filter_queryset(self, queryset): "created_by__profile", "parent_topic", "parent_board", + "parent_board__group", ).prefetch_related( "attachments", models.Prefetch(