From 6ca66fc2cd90d447e845538d80d2d3ea56a36487 Mon Sep 17 00:00:00 2001 From: Adam Radwon <3501229+radwon@users.noreply.github.com> Date: Sun, 9 Apr 2023 13:04:27 +0000 Subject: [PATCH 1/2] Use the new STORAGES setting in Django 4.2 In Django 4.2 the django.core.files.storage.get_storage_class() function is deprecated as well as the STATICFILES_STORAGE setting in favor of STORAGES["staticfiles"]. Use django.core.files.storage.storages to get the configured storage class for static files instead. For Django versions prior to 4.2 keep using the django.core.files.storage.get_storage_class() function for backwards compatibility. Fixes #1758 --- debug_toolbar/panels/staticfiles.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/debug_toolbar/panels/staticfiles.py b/debug_toolbar/panels/staticfiles.py index c02194071..bee336249 100644 --- a/debug_toolbar/panels/staticfiles.py +++ b/debug_toolbar/panels/staticfiles.py @@ -3,7 +3,6 @@ from django.conf import settings from django.contrib.staticfiles import finders, storage from django.core.checks import Warning -from django.core.files.storage import get_storage_class from django.utils.functional import LazyObject from django.utils.translation import gettext_lazy as _, ngettext @@ -53,7 +52,17 @@ class DebugConfiguredStorage(LazyObject): """ def _setup(self): - configured_storage_cls = get_storage_class(settings.STATICFILES_STORAGE) + try: + # From Django 4.2 use django.core.files.storage.storages in favor + # of the deprecated django.core.files.storage.get_storage_class + from django.core.files.storage import storages + + configured_storage_cls = storages["staticfiles"].__class__ + except ImportError: + # Backwards compatibility for Django versions prior to 4.2 + from django.core.files.storage import get_storage_class + + configured_storage_cls = get_storage_class(settings.STATICFILES_STORAGE) class DebugStaticFilesStorage(configured_storage_cls): def __init__(self, collector, *args, **kwargs): From db14656b61011f9be47108269fc4bfd9b0b21d1a Mon Sep 17 00:00:00 2001 From: Adam Radwon <3501229+radwon@users.noreply.github.com> Date: Sun, 9 Apr 2023 18:12:46 +0000 Subject: [PATCH 2/2] Use the new STORAGES setting in Django 4.2 Use the new STORAGES setting in Django 4.2 In Django 4.2 the django.core.files.storage.get_storage_class() function is deprecated as well as the STATICFILES_STORAGE setting in favor of STORAGES["staticfiles"]. Use django.core.files.storage.storages to get the configured storage class for static files instead. For Django versions prior to 4.2 keep using the django.core.files.storage.get_storage_class() function for backwards compatibility. Fixes #1758 --- docs/changes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changes.rst b/docs/changes.rst index 1e6070e84..b51a5493c 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,8 @@ Change log Pending ------- +* Added support for the new STORAGES setting in Django 4.2 for static files. + 4.0.0 (2023-04-03) ------------------