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