kobotoolbox / kobocat

Our (backend) server for providing blank forms to Collect and Enketo and for receiving and storing submissions.
BSD 2-Clause "Simplified" License
117 stars 127 forks source link

Code refactoring: Use `default_storage` instead of `get_storage_class()()` #886

Closed noliveleger closed 1 year ago

noliveleger commented 1 year ago

Description

Django provides a default_storage variable which exactly what get_storage_class()() is doing. See https://github.com/django/django/blob/3.2/django/core/files/storage.py#L362-L367

noliveleger commented 1 year ago

@noliveleger there are still some uses in this branch of get_storage_class, (which I see is deprecated in Django 4.2), but I don't think that's an obstacle to merging.

$ rg get_storage_class
onadata/apps/logger/management/commands/move_media_to_s3.py
22:            fs = get_storage_class(
24:            s3 = get_storage_class('storages.backends.s3boto3.S3Boto3Storage')()

onadata/apps/logger/management/commands/change_s3_media_permissions.py
7:from django.core.files.storage import get_storage_class
26:            s3 = get_storage_class('storages.backends.s3boto3.S3Boto3Storage')()

onadata/libs/utils/viewer_tools.py
196:            storage_class = get_storage_class()

I left the first two in purpose because it was calling a specific storage class. Thanks for your link. I did not know it was deprecated with 4.2 For the latter, @JacquelineMorrissette already spotted it, I thought I removed it already. My bad!