Skip to content

Commit

Permalink
add conditional settings and new env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscobmacedo committed Mar 28, 2024
1 parent ec00724 commit 77edeec
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 15 deletions.
14 changes: 14 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DJANGO_ENV=development
DEBUG=true

DJANGO_SECRET_KEY="your_secret_key"
ALLOWED_HOSTS=localhost,127.0.0.1

SQL_ENGINE=django.db.backends.postgresql
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5432
POSTGRES_DB=postgres
DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}

4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ jobs:

- name: Test
run: |
poetry run python manage.py test
poetry run python manage.py test
env:
DJANGO_ENV: github_actions
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ This tool is expected to read the data from a remote source (an S3 bucket or sim
# Local Setup
You need to have [python](https://www.python.org/) and [poetry](https://python-poetry).


3. Install dependencies with `poetry install`;
4. Launch a poetry shell so the virtual environment is active: `poetry shell`;
5. Run `python manage.py migrate` to create the databases tables;
6. Add the pre-commit hook by running `pre-commit install`. This will ensure your code is formatted before you commit something;
1. Create an `.env` file by copying the `.env.example` one and editing the variables as needed.
2. Install dependencies with `poetry install`;
3. Launch a poetry shell so the virtual environment is active: `poetry shell`;
4. Run `python manage.py migrate` to create the databases tables;
5. Add the pre-commit hook by running `pre-commit install`. This will ensure your code is formatted before you commit something;

## Load fixtures
To load some dummy data, run:
Expand Down
12 changes: 12 additions & 0 deletions dm_regional_site/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from decouple import config

DJANGO_ENV = config("DJANGO_ENV", default="production")

if DJANGO_ENV == "development":
from .development import * # NOQA

elif DJANGO_ENV == "github_actions":
from .github_actions import * # NOQA

else:
from .production import * # NOQA
26 changes: 17 additions & 9 deletions dm_regional_site/settings.py → dm_regional_site/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

from pathlib import Path

import dj_database_url
from decouple import config

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand All @@ -20,12 +23,16 @@
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-gh4wp!kqd8#nc6_o)eqxs@_4w2+9+p(rq$bdz&d2*!jg946@w3"

SECRET_KEY = config(
"DJANGO_SECRET_KEY",
default="django-insecure-gh4wp!kqd8#nc6_o)eqxs@_4w2+9+p(rq$bdz&d2*!jg946@w3",
)
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = config("DEBUG", default=False, cast=bool)

ALLOWED_HOSTS = []
ALLOWED_HOSTS = config(
"ALLOWED_HOSTS", cast=lambda v: [s.strip() for s in v.split(",")], default=""
)


# Application definition
Expand Down Expand Up @@ -84,12 +91,13 @@

# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

MAX_CONN_AGE = 600
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
"default": dj_database_url.config(
default=config("DATABASE_URL", f"sqlite:///{BASE_DIR}/db.sqlite3"),
conn_max_age=MAX_CONN_AGE,
ssl_require=False,
),
}


Expand Down
3 changes: 3 additions & 0 deletions dm_regional_site/settings/development.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .base import * # NOQA

# add development dedicated settings here
3 changes: 3 additions & 0 deletions dm_regional_site/settings/github_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .base import * # NOQA

# add github actions dedicated settings here
7 changes: 7 additions & 0 deletions dm_regional_site/settings/production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import django_heroku

from .base import * # NOQA

django_heroku.settings(locals())

# add production dedicated settings here

0 comments on commit 77edeec

Please sign in to comment.