Ticket #22337: FileSystemStorage_deconstruct.patch

File FileSystemStorage_deconstruct.patch, 1.1 KB (added by nliberg, 11 months ago)

Add deconstruct method to django.core.files.storage.FileSystemStorage

  • django/core/files/storage.py

    diff --git a/django/core/files/storage.py b/django/core/files/storage.py
    index ade1817..4f1a8ab 100644
    a b class FileSystemStorage(Storage): 
    167167            else settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS
    168168        )
    169169
     170    def deconstruct(self):
     171        kwargs = {}
     172        # add items with non-default values
     173        if self.base_location != settings.MEDIA_ROOT:
     174            kwargs['location'] = self.location
     175        if self.base_url != settings.MEDIA_URL:
     176            kwargs['base_url'] = self.base_url
     177        if self.file_permissions_mode != settings.FILE_UPLOAD_PERMISSIONS:
     178            kwargs['file_permissions_mode'] = self.file_permissions_mode
     179        if self.directory_permissions_mode != settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS:
     180            kwargs['directory_permissions_mode'] = directory_permissions_mode
     181        return ('django.core.files.storage.FileSystemStorage', [], kwargs)
     182
    170183    def _open(self, name, mode='rb'):
    171184        return File(open(self.path(name), mode))
    172185
Back to Top