7 changed files with 153 additions and 158 deletions
@ -1,52 +1,49 @@
|
||||
# -*- coding: utf-8 -*- |
||||
from __future__ import unicode_literals |
||||
# # -*- coding: utf-8 -*- |
||||
# from __future__ import unicode_literals |
||||
|
||||
import os |
||||
import warnings |
||||
from django.conf import settings |
||||
from django.core.files.storage import FileSystemStorage |
||||
from django.utils._os import safe_join |
||||
from django.utils.six.moves.urllib.parse import urljoin |
||||
# import os |
||||
# import warnings |
||||
# from django.conf import settings |
||||
# from django.core.files.storage import FileSystemStorage |
||||
# from django.utils._os import safe_join |
||||
|
||||
|
||||
ORIGINAL_FILE_PREFIX = 'original' |
||||
CACHED_VARIANT_PREFIX = 'cache' |
||||
MANUAL_VARIANT_PREFIX = 'manual' |
||||
|
||||
# ORIGINAL_FILE_PREFIX = 'original' |
||||
# CACHED_VARIANT_PREFIX = 'cache' |
||||
# MANUAL_VARIANT_PREFIX = 'manual' |
||||
|
||||
# TODO ? @deconstructible |
||||
class ProtectedMediaAssetStorage(FileSystemStorage): |
||||
""" |
||||
Alllows uploads to /original/-subdirectories, but never provides URLs |
||||
to those files, instead raising an error. |
||||
""" |
||||
|
||||
ORIGINAL_FILE_PREFIX = ORIGINAL_FILE_PREFIX |
||||
# # TODO ? @deconstructible |
||||
# class ProtectedMediaAssetStorage(FileSystemStorage): |
||||
# """ |
||||
# Alllows uploads to /original/-subdirectories, but never provides URLs |
||||
# to those files, instead raising an error. |
||||
# """ |
||||
|
||||
def __init__(self, location=None, base_url=None, **kwargs): |
||||
if location is None: |
||||
location = getattr(settings, 'PROTECTED_MEDIA_ASSETS_ROOT', settings.PROTECTED_MEDIA_ASSETS_ROOT) |
||||
super(ProtectedMediaAssetStorage, self).__init__(location=location, base_url=None, **kwargs) |
||||
self.base_url = None |
||||
# ORIGINAL_FILE_PREFIX = ORIGINAL_FILE_PREFIX |
||||
# FILENAME_MAX_LENGTH = FILENAME_MAX_LENGTH |
||||
|
||||
def delete(self, name): |
||||
super(ProtectedMediaAssetStorage, self).delete(name) |
||||
# FIXME Delete all cached files, too |
||||
warnings.warn("Cached files for asset \"%s\" are not deleted." % name) |
||||
# def __init__(self, location=None, base_url=None, **kwargs): |
||||
# if location is None: |
||||
# location = getattr(settings, 'PROTECTED_MEDIA_ROOT', settings.PROTECTED_MEDIA_ROOT) |
||||
# super(ProtectedMediaAssetStorage, self).__init__(location=location, base_url=None, **kwargs) |
||||
|
||||
def path(self, name): |
||||
""" |
||||
`name` must already contain the whole asset filesystem path. |
||||
""" |
||||
return safe_join(self.location, ORIGINAL_FILE_PREFIX, name) |
||||
# def delete(self, name): |
||||
# super(ProtectedMediaAssetStorage, self).delete(name) |
||||
# # FIXME Delete all cached files, too |
||||
# warnings.warn("Cached files for asset \"%s\" are not deleted." % name) |
||||
|
||||
def size(self, name): |
||||
return os.path.getsize(self.path(name)) |
||||
# def path(self, name): |
||||
# """ |
||||
# `name` must already contain the whole asset filesystem path. |
||||
# """ |
||||
# return safe_join(self.location, ORIGINAL_FILE_PREFIX, name) |
||||
|
||||
def url(self, name): |
||||
raise ValueError("This file storage is not accessible via a URL.") |
||||
# def size(self, name): |
||||
# return os.path.getsize(self.path(name)) |
||||
|
||||
|
||||
# TODO ? @deconstructible |
||||
# class |
||||
# return urljoin(self.base_url, ORIGINAL_FILE_PREFIX, filepath_to_uri(name)) |
||||
# # def url(self, name): |
||||
# # print "storage.url" |
||||
# # # Returns the URL for fetching the original file |
||||
# # raise ValueError("This file storage is not accessible via a URL.") |
||||
|
Loading…
Reference in new issue