Skip to content

Commit

Permalink
Drop DEFAULT_FILE_STORAGE/STATICFILES_STORAGE in django 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Dec 30, 2023
1 parent 90355ca commit 67e6636
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
54 changes: 45 additions & 9 deletions app_helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import string
import sys
import warnings
from tempfile import mkdtemp
from unittest.mock import patch

Expand All @@ -12,18 +13,16 @@
from django.core.management import call_command
from django.urls import clear_url_caches
from django.utils.functional import empty
from setuptools._distutils.version import LooseVersion

from . import HELPER_FILE

try:
from setuptools import LooseVersion
except ImportError: # pragma: no cover
from distutils.version import LooseVersion

try:
import cms # NOQA

CMS = True
CMS_42 = LooseVersion("4.2") <= LooseVersion(cms.__version__) < LooseVersion("4.3")
CMS_41 = LooseVersion("4.1") <= LooseVersion(cms.__version__) < LooseVersion("4.2")
CMS_40 = LooseVersion("4.0") <= LooseVersion(cms.__version__) < LooseVersion("4.1")
CMS_311 = LooseVersion("3.11") <= LooseVersion(cms.__version__) < LooseVersion("4.0")
CMS_310 = LooseVersion("3.10") <= LooseVersion(cms.__version__) < LooseVersion("3.11")
Expand All @@ -39,6 +38,8 @@
CMS_30 = LooseVersion("3.0") <= LooseVersion(cms.__version__) < LooseVersion("3.1")
except ImportError: # pragma: no cover
CMS = False
CMS_42 = False
CMS_41 = False
CMS_40 = False
CMS_311 = False
CMS_310 = False
Expand All @@ -53,10 +54,16 @@
CMS_31 = False
CMS_30 = False

DJANGO_2_2 = LooseVersion(django.get_version()) < LooseVersion("3.0")
DJANGO_3_0 = LooseVersion(django.get_version()) < LooseVersion("3.1")
DJANGO_3_1 = LooseVersion(django.get_version()) < LooseVersion("3.2")
DJANGO_3_2 = LooseVersion(django.get_version()) < LooseVersion("4.0")
DJANGO_2_2 = LooseVersion("2.2") <= LooseVersion(django.get_version()) < LooseVersion("3.0")
DJANGO_3_0 = LooseVersion("3.0") <= LooseVersion(django.get_version()) < LooseVersion("3.1")
DJANGO_3_1 = LooseVersion("3.1") <= LooseVersion(django.get_version()) < LooseVersion("3.2")
DJANGO_3_2 = LooseVersion("3.2") <= LooseVersion(django.get_version()) < LooseVersion("4.0")
DJANGO_4_0 = LooseVersion("4.0") <= LooseVersion(django.get_version()) < LooseVersion("4.1")
DJANGO_4_1 = LooseVersion("4.1") <= LooseVersion(django.get_version()) < LooseVersion("4.2")
DJANGO_4_2 = LooseVersion("4.2") <= LooseVersion(django.get_version()) < LooseVersion("5.0")
DJANGO_5_0 = LooseVersion("5.0") <= LooseVersion(django.get_version()) < LooseVersion("5.1")
DJANGO_5_1 = LooseVersion("5.1") <= LooseVersion(django.get_version()) < LooseVersion("5.2")
DJANGO_5_2 = LooseVersion("5.2") <= LooseVersion(django.get_version()) < LooseVersion("6.0")


def load_from_file(module_path):
Expand Down Expand Up @@ -300,7 +307,36 @@ def _make_settings(args, application, settings, STATIC_ROOT, MEDIA_ROOT): # NOQ
default_settings["DEFAULT_AUTO_FIELD"] = "django.db.models.BigAutoField"

_reset_django(settings)
is_file_storage_defined = "DEFAULT_FILE_STORAGE" in extra_settings
is_staticfiles_storage_defined = "STATICFILES_STORAGE" in extra_settings
settings.configure(**default_settings)
django_has_file_storage = hasattr(settings, "DEFAULT_FILE_STORAGE")
django_has_staticfile_storage = hasattr(settings, "STATICFILES_STORAGE")
django_has_storages = hasattr(settings, "STORAGES")
if django_has_file_storage and django_has_storages and not is_file_storage_defined:
del settings.DEFAULT_FILE_STORAGE
try:
from django.utils.deprecation import RemovedInDjango51Warning

warnings.warn(
"DEFAULT_FILE_STORAGE is deprecated in Django 4.2, use the STORAGES setting instead.",
"DEFAULT_FILE_STORAGE is going to be removed from project settings",
RemovedInDjango51Warning,
)
except ImportError:
pass
if django_has_staticfile_storage and django_has_storages and not is_staticfiles_storage_defined:
del settings.STATICFILES_STORAGE
try:
from django.utils.deprecation import RemovedInDjango51Warning

warnings.warn(
"STATICFILES_STORAGE is deprecated in Django 4.2, use the STORAGES setting instead.",
"STATICFILES_STORAGE is going to be removed from project settings",
RemovedInDjango51Warning,
)
except ImportError:
pass
django.setup()
reload_urls(settings, cms_apps=False)
return settings
Expand Down
1 change: 1 addition & 0 deletions changes/255.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop DEFAULT_FILE_STORAGE/STATICFILES_STORAGE in django 4.2
7 changes: 7 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ An alternative, and possibly clearer form is::

By default any setting option provided in ``helper.py`` will override the default ones.

.. warning:: On Django 4.2 and up you **cannot** use ``DEFAULT_FILE_STORAGE`` and ``STATICFILES_STORAGE``
in ``HELPER_SETTINGS``. ``DEFAULT_FILE_STORAGE`` and ``STATICFILES_STORAGE`` are deprecated and
``django-app-helper`` will remove it from ``HELPER_SETTINGS`` due to compatibility issues.

Use ``STORAGES`` setting instead.


Special settings
================

Expand Down

0 comments on commit 67e6636

Please sign in to comment.