Skip to content

Storage

hypha.apply.utils.storage

private_file_storage module-attribute

private_file_storage = getattr(settings, 'PRIVATE_FILE_STORAGE', None)

PrivateStorage module-attribute

PrivateStorage = get_storage_class(private_file_storage)

PrivateMediaView

Bases: LoginRequiredMixin, View

Base view to configure the access to private media stored in the private storage location.

Classes inheriting from this should implement their own access requirements based on the file being served, this class will only ensure that the file is not made public to unauthenticated users.

storage class-attribute instance-attribute

storage = PrivateStorage()

get_media

get_media(*args, **kwargs)

Convert the URL request to a path and then return the file object

e.g. storage_location = get_my_storage_location(request, **args, **kwargs) return self.storage.open(storage_location)

Source code in hypha/apply/utils/storage.py
def get_media(self, *args, **kwargs):
    """
    Convert the URL request to a path and then return the file object

    e.g.
    storage_location = get_my_storage_location(request, **args, **kwargs)
    return self.storage.open(storage_location)
    """
    raise NotImplementedError()

get

get(*args, **kwargs)
Source code in hypha/apply/utils/storage.py
def get(self, *args, **kwargs):
    file_to_serve = self.get_media(*args, **kwargs)
    return FileResponse(file_to_serve)