From a6d041f0fd38500ee0481faea7429be44805a17f Mon Sep 17 00:00:00 2001 From: cquinn540 Date: Thu, 7 Nov 2024 14:41:33 -0500 Subject: [PATCH 1/3] fix: use env variable to run django locally --- .env.dev.local | 1 + .gitignore | 1 + backend/backend/settings.py | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .env.dev.local diff --git a/.env.dev.local b/.env.dev.local new file mode 100644 index 000000000..be6a117c6 --- /dev/null +++ b/.env.dev.local @@ -0,0 +1 @@ +DATABASE_HOST="localhost" diff --git a/.gitignore b/.gitignore index fc1bf385b..e34fe82ea 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ frontend/.github/ .env .env.* !.env.dev +!.env.dev.local dist # Node dependencies diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 94c45627a..31eaa458e 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -17,7 +17,14 @@ from rest_framework.settings import api_settings django_stubs_ext.monkeypatch(extra_classes=(viewsets.ModelViewSet,)) -dotenv.load_dotenv() + +PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent + +if os.getenv("DJANGO_ENV") == "LOCAL_DEV": + dotenv.load_dotenv(override=True, dotenv_path=PROJECT_ROOT / ".env.dev") + dotenv.load_dotenv(override=True, dotenv_path=PROJECT_ROOT / ".env.dev.local") +else: + dotenv.load_dotenv() DATABASE_HOST = os.getenv("DATABASE_HOST") From a3260d5a2c3b9cd55c088c51214a3a5968234878 Mon Sep 17 00:00:00 2001 From: cquinn540 Date: Thu, 7 Nov 2024 14:45:19 -0500 Subject: [PATCH 2/3] docs: switch between local and compose with just env variable --- CONTRIBUTING.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2142b0e13..7e663fbe4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -238,15 +238,14 @@ Our backend depends on a connection to a postgres DB, therefore we need to setup docker compose --env-file .env.dev up db ``` -In order to connect to the DB, we need to change the `DATABASE_HOST` environment variable inside the `.env.dev` file first. +To run locally, set the environment variable `DJANGO_ENV` to `LOCAL_DEV`: ```bash -# Current -DATABASE_HOST=db -# Changed -DATABASE_HOST=localhost +export DJANGO_ENV=LOCAL_DEV ``` +When this is set, django will load environment variables from `env.dev` first, and then from `.env.dev.local` which will overwrite some variables for local development. + From here we need the project's dependencies, with the practice being to create a virtual environment first within your local activist directory and then install the dependencies within it: On Unix or MacOS, run: From 91f6155ad874f0284b7bedbbb24224e54edaf8c7 Mon Sep 17 00:00:00 2001 From: cquinn540 Date: Thu, 7 Nov 2024 17:11:57 -0500 Subject: [PATCH 3/3] fix: fix type errors --- backend/entities/admin.py | 8 ++++---- backend/entities/serializers.py | 3 ++- frontend/components/menu/MenuItemLabel.vue | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/entities/admin.py b/backend/entities/admin.py index eb615f76d..b89219522 100644 --- a/backend/entities/admin.py +++ b/backend/entities/admin.py @@ -43,19 +43,19 @@ # MARK: Methods -class GroupAdmin(admin.ModelAdmin): +class GroupAdmin(admin.ModelAdmin[Group]): list_display = ["group_name", "name"] -class GroupTextAdmin(admin.ModelAdmin): +class GroupTextAdmin(admin.ModelAdmin[GroupText]): list_display = ["id", "group_id"] -class OrganizationAdmin(admin.ModelAdmin): +class OrganizationAdmin(admin.ModelAdmin[Organization]): list_display = ["org_name", "name"] -class OrganizationTextAdmin(admin.ModelAdmin): +class OrganizationTextAdmin(admin.ModelAdmin[OrganizationText]): list_display = ["id", "org_id"] diff --git a/backend/entities/serializers.py b/backend/entities/serializers.py index bff553d89..b70e4fb77 100644 --- a/backend/entities/serializers.py +++ b/backend/entities/serializers.py @@ -40,7 +40,8 @@ class Meta: class OrganizationTextSerializer(serializers.ModelSerializer[OrganizationText]): - orgID = serializers.StringRelatedField(source="org_id.id") + # mypy thinks a generic type argument is needed for StringRelatedField + orgID = serializers.StringRelatedField(source="org_id.id") # type: ignore[var-annotated] class Meta: model = OrganizationText diff --git a/frontend/components/menu/MenuItemLabel.vue b/frontend/components/menu/MenuItemLabel.vue index 3d8570f23..fe32fa0aa 100644 --- a/frontend/components/menu/MenuItemLabel.vue +++ b/frontend/components/menu/MenuItemLabel.vue @@ -1,7 +1,7 @@