From c3a7915b60918eb907b43aac5f620cdf50a96d98 Mon Sep 17 00:00:00 2001 From: Dimitar Todorov Date: Mon, 15 May 2023 13:43:00 +0300 Subject: [PATCH 1/2] Adjust to 4.2 deprecations and errors --- config/django/base.py | 9 +-------- config/settings/files_and_storages.py | 15 ++++++++++++++- styleguide_example/common/models.py | 2 +- styleguide_example/testing_examples/models.py | 2 +- .../testing_examples/selectors/schools.py | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/config/django/base.py b/config/django/base.py index 8d03232d..94ea9b4e 100644 --- a/config/django/base.py +++ b/config/django/base.py @@ -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 = { @@ -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 @@ -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', diff --git a/config/settings/files_and_storages.py b/config/settings/files_and_storages.py index fd2ce2d1..3d090e1a 100644 --- a/config/settings/files_and_storages.py +++ b/config/settings/files_and_storages.py @@ -3,6 +3,19 @@ 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")) @@ -16,7 +29,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") diff --git a/styleguide_example/common/models.py b/styleguide_example/common/models.py index 1a1cf93d..160b8840 100644 --- a/styleguide_example/common/models.py +++ b/styleguide_example/common/models.py @@ -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 diff --git a/styleguide_example/testing_examples/models.py b/styleguide_example/testing_examples/models.py index 47dd3d57..f08180c7 100644 --- a/styleguide_example/testing_examples/models.py +++ b/styleguide_example/testing_examples/models.py @@ -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): diff --git a/styleguide_example/testing_examples/selectors/schools.py b/styleguide_example/testing_examples/selectors/schools.py index 85cdb0a4..0acd1643 100644 --- a/styleguide_example/testing_examples/selectors/schools.py +++ b/styleguide_example/testing_examples/selectors/schools.py @@ -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 From c9ac284bd28467ca189739e5365ee0a71a71889b Mon Sep 17 00:00:00 2001 From: Radoslav Georgiev Date: Sun, 12 May 2024 17:13:32 +0300 Subject: [PATCH 2/2] Fix ruff errors --- config/settings/files_and_storages.py | 1 - 1 file changed, 1 deletion(-) diff --git a/config/settings/files_and_storages.py b/config/settings/files_and_storages.py index 3d090e1a..252e5fcc 100644 --- a/config/settings/files_and_storages.py +++ b/config/settings/files_and_storages.py @@ -3,7 +3,6 @@ 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")