Skip to content

Commit

Permalink
chore(conf): update storages configuration
Browse files Browse the repository at this point in the history
Update [Django Storages](https://docs.djangoproject.com/en/4.2/ref/settings/#storages) configuration to use the new setting added in [Django 4.2](https://docs.djangoproject.com/en/4.2/releases/4.2/#custom-file-storages).

Included also is an update of pyscopg to [version 3](https://www.psycopg.org/psycopg3/docs/basic/install.html) as this is now supported in [Django 4.2](https://docs.djangoproject.com/en/4.2/releases/4.2/#psycopg-3-support).

Included also are other minor improvements and fixes.
  • Loading branch information
kennedykori committed Apr 5, 2023
1 parent 7f96982 commit 680fdcd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
9 changes: 7 additions & 2 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
LANGUAGE_CODE = "en-us"
TIME_ZONE = "Africa/Nairobi"
USE_I18N = True
# USE_L10N = True
USE_L10N = True
USE_TZ = True


Expand All @@ -223,7 +223,12 @@
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"compressor.finders.CompressorFinder",
]
STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"
STORAGES = {
"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}

WHITENOISE_MANIFEST_STRICT = False

Expand Down
22 changes: 2 additions & 20 deletions config/settings/github_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,15 @@
"NAME": env.str("POSTGRES_DB"),
"USER": env.str("POSTGRES_USER"),
"PASSWORD": env.str("POSTGRES_PASSWORD"),
"HOST": env.str("POSTGRES_HOST"),
"PORT": env.str("POSTGRES_PORT", None),
"HOST": env.str("POSTGRES_HOST", default="localhost"),
"PORT": env.int("POSTGRES_PORT", default=5432),
"ENGINE": "django.contrib.gis.db.backends.postgis",
"ATOMIC_REQUESTS": True,
"CONN_MAX_AGE": env.int("CONN_MAX_AGE", default=60)
},
}


###############################################################################
# STORAGES
###############################################################################

INSTALLED_APPS += ["storages"]
GS_BUCKET_NAME = env.str("DJANGO_GCP_STORAGE_BUCKET_NAME")
GS_DEFAULT_ACL = "project-private"


###############################################################################
# DJANGO COMPRESSOR
###############################################################################
Expand All @@ -52,12 +43,3 @@
],
"js": ["compressor.filters.jsmin.JSMinFilter"],
}


###############################################################################
# STATIC ASSETS AND MEDIA FILES
###############################################################################

DEFAULT_FILE_STORAGE = "utils.storages.MediaRootGoogleCloudStorage"
MEDIA_URL = "https://storage.googleapis.com/%s/media/" % GS_BUCKET_NAME
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
4 changes: 2 additions & 2 deletions config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"NAME": env.str("POSTGRES_DB"),
"USER": env.str("POSTGRES_USER"),
"PASSWORD": env.str("POSTGRES_PASSWORD"),
"HOST": env.str("POSTGRES_HOST"),
"PORT": env.str("POSTGRES_PORT", None),
"HOST": env.str("POSTGRES_HOST", defualt="localhost"),
"PORT": env.int("POSTGRES_PORT", default=5432),
"ENGINE": "django.contrib.gis.db.backends.postgis",
"ATOMIC_REQUESTS": True,
},
Expand Down
14 changes: 9 additions & 5 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"USER": env.str("POSTGRES_USER"),
"PASSWORD": env.str("POSTGRES_PASSWORD"),
"HOST": env.str("POSTGRES_HOST"),
"PORT": env.str("POSTGRES_PORT", None),
"PORT": env.str("POSTGRES_PORT", default=None),
"ENGINE": "django.contrib.gis.db.backends.postgis",
"ATOMIC_REQUESTS": False,
"CONN_HEALTH_CHECKS": True,
Expand Down Expand Up @@ -155,10 +155,12 @@
# STATIC ASSETS AND MEDIA FILES
###############################################################################

DEFAULT_FILE_STORAGE = "utils.storages.MediaRootGoogleCloudStorage"
MEDIA_URL = "https://storage.googleapis.com/%s/media/" % GS_BUCKET_NAME
STATIC_URL = "https://storage.googleapis.com/%s/static/" % GS_BUCKET_NAME
STATICFILES_STORAGE = "utils.storages.StaticRootGoogleCloudStorage"
STORAGES = {
"default": {"BACKEND": "utils.storages.MediaRootGoogleCloudStorage"},
"staticfiles": {"BACKEND": "utils.storages.StaticRootGoogleCloudStorage"},
}


###############################################################################
Expand All @@ -177,9 +179,11 @@
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
COMPRESS_OFFLINE = True
# https://django-compressor.readthedocs.io/en/stable/settings.html#django.conf.settings.COMPRESS_OFFLINE_MANIFEST_STORAGE
COMPRESS_OFFLINE_MANIFEST_STORAGE = STATICFILES_STORAGE
COMPRESS_OFFLINE_MANIFEST_STORAGE = (
"utils.storages.StaticRootGoogleCloudStorage"
)
# https://django-compressor.readthedocs.io/en/stable/settings.html#django.conf.settings.COMPRESS_STORAGE
COMPRESS_STORAGE = STATICFILES_STORAGE
COMPRESS_STORAGE = "utils.storages.StaticRootGoogleCloudStorage"
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL
COMPRESS_URL = STATIC_URL

Expand Down
22 changes: 14 additions & 8 deletions config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@

DATABASES = {
"default": {
"NAME": env.str("TEST_POSTGRES_DB"),
"USER": env.str("TEST_POSTGRES_USER"),
"PASSWORD": env.str("TEST_POSTGRES_PASSWORD"),
"HOST": env.str("TEST_POSTGRES_HOST"),
"PORT": env.str("TEST_POSTGRES_PORT", None),
"NAME": env.str(
"TEST_POSTGRES_DB", default=f"test_{env.str('POSTGRES_DB')}"
),
"USER": env.str(
"TEST_POSTGRES_USER", default=env.str("POSTGRES_USER")
),
"PASSWORD": env.str(
"TEST_POSTGRES_PASSWORD", defualt=env.str("POSTGRES_PASSWORD")
),
"HOST": env.str("TEST_POSTGRES_HOST", default="localhost"),
"PORT": env.int("TEST_POSTGRES_PORT", port=5432),
"ENGINE": "django.contrib.gis.db.backends.postgis",
"ATOMIC_REQUESTS": True,
"TEST": {
"NAME": env.str("TEST_POSTGRES_DB"),
"USER": env.str("TEST_POSTGRES_USER"),
"PASSWORD": env.str("TEST_POSTGRES_PASSWORD"),
"NAME": env.str(
"TEST_POSTGRES_DB", default=f"test_{env.str('POSTGRES_DB')}"
)
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ environs~=9.5.0
google-auth~=2.17.1
google-cloud-pubsub~=2.15.2
openpyxl~=3.1.2
psycopg2~=2.9.5
psycopg-binary~=3.1.8
pyexcel-io~=0.6.6
pyexcel-xlsx~=0.6.0
pyexcel~=0.7.0
Expand Down

0 comments on commit 680fdcd

Please sign in to comment.