Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Staticfiles Configurations in Django 4.2+ and Required Settings Update #360

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions config/django/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
DATABASES = {
"default": env.db("DATABASE_URL", default="postgres:///styleguide_example"),
}
DATABASES["default"]["ATOMIC_REQUESTS"] = True

if os.environ.get("GITHUB_WORKFLOW"):
DATABASES = {
Expand All @@ -121,7 +122,6 @@
"PORT": "5432",
}
}
DATABASES["default"]["ATOMIC_REQUESTS"] = True

# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -156,13 +156,6 @@

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATIC_URL = "/static/"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

REST_FRAMEWORK = {
"EXCEPTION_HANDLER": "styleguide_example.api.exception_handlers.drf_default_with_modifications_exception_handler",
# 'EXCEPTION_HANDLER': 'styleguide_example.api.exception_handlers.hacksoft_proposed_exception_handler',
Expand Down
14 changes: 13 additions & 1 deletion config/settings/files_and_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
from config.env import BASE_DIR, env, env_to_enum
from styleguide_example.files.enums import FileUploadStorage, FileUploadStrategy

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATIC_URL = "/static/"
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage"},
}


FILE_UPLOAD_STRATEGY = env_to_enum(FileUploadStrategy, env("FILE_UPLOAD_STRATEGY", default="standard"))
FILE_UPLOAD_STORAGE = env_to_enum(FileUploadStorage, env("FILE_UPLOAD_STORAGE", default="local"))

Expand All @@ -16,7 +28,7 @@
if FILE_UPLOAD_STORAGE == FileUploadStorage.S3:
# Using django-storages
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
STORAGES["default"] = {"BACKEND": "storages.backends.s3boto3.S3Boto3Storage"}

AWS_S3_ACCESS_KEY_ID = env("AWS_S3_ACCESS_KEY_ID")
AWS_S3_SECRET_ACCESS_KEY = env("AWS_S3_SECRET_ACCESS_KEY")
Expand Down
2 changes: 1 addition & 1 deletion styleguide_example/common/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.db.models import F, Q
from django.db.models.query import F, Q
from django.utils import timezone


Expand Down
2 changes: 1 addition & 1 deletion styleguide_example/testing_examples/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from uuid import uuid4

from django.db import models
from django.db.models import F, Q
from django.db.models.query import F, Q


class School(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion styleguide_example/testing_examples/selectors/schools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional

from django.core.exceptions import ValidationError
from django.db.models import Q, QuerySet
from django.db.models.query import Q, QuerySet

from styleguide_example.testing_examples.models import School, SchoolCourse

Expand Down
Loading