This commit is contained in:
2018-04-09 11:33:16 +02:00
parent 277851681b
commit ef2c114f35
7 changed files with 60 additions and 89 deletions

View File

@@ -6,12 +6,11 @@ from django.core.files.storage import default_storage
from django.conf import settings
from django.db import models
from django.core.urlresolvers import reverse_lazy
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from image_cropping import ImageRatioField
from parler.models import TranslatableModel, TranslatedFields
#from portal.storage import PrivateS3MediaStorage
from portal.storage import PrivateS3MediaStorage
from project.utils import CroppableFilerImageField
@@ -92,8 +91,7 @@ class DownloadTag(TranslatableModel):
if getattr(settings, 'DEFAULT_STORAGE_DSN', None):
# protected_file_storage = PrivateS3MediaStorage()
protected_file_storage = default_storage
protected_file_storage = PrivateS3MediaStorage()
else:
protected_file_storage = default_storage

View File

@@ -1,58 +1,57 @@
# -*- coding: utf-8 -*-
#import re
#from aldryn_django.storage import S3MediaStorage
#from django.conf import settings
#
#from boto.s3.connection import (
# SubdomainCallingFormat,
# OrdinaryCallingFormat,
#)
#
#
#class PrivateS3MediaStorage(S3MediaStorage):
# def __init__(self):
# bucket_name = settings.AWS_MEDIA_STORAGE_BUCKET_NAME
#
# if '.' in bucket_name:
# calling_format = OrdinaryCallingFormat()
# else:
# calling_format = SubdomainCallingFormat()
#
# # We cannot use a function call or a partial here. Instead, we have to
# # create a subclass because django tries to recreate a new object by
# # calling the __init__ of the returned object (with no arguments).
# super(S3MediaStorage, self).__init__(
# access_key=settings.AWS_MEDIA_ACCESS_KEY_ID,
# secret_key=settings.AWS_MEDIA_SECRET_ACCESS_KEY,
# bucket_name=bucket_name,
# location=settings.AWS_MEDIA_BUCKET_PREFIX,
# host=settings.AWS_MEDIA_STORAGE_HOST,
# custom_domain=settings.AWS_MEDIA_DOMAIN,
# calling_format=calling_format,
# # Setting an ACL requires us to grant the user the PutObjectAcl
# # permission as well, even if it matches the default bucket ACL.
# # XXX: Ideally we would thus set it to `None`, but due to how
# # easy_thumbnails works internally, that causes thumbnail
# # generation to fail...
# default_acl='private',
# querystring_auth=True,
# )
# # MEDIA_HEADERS is a list of tuples containing a regular expression
# # to match against a path, and a dictionary of HTTP headers to be
# # returned with the resource identified by the path when it is
# # requested.
# # The headers are applied in the order they where declared, and
# # processing stops at the first match.
# # E.g.:
# #
# # MEDIA_HEADERS = [
# # (r'media/cache/.*', {
# # 'Cache-Control': 'max-age={}'.format(3600 * 24 * 365),
# # })
# # ]
# #
# media_headers = getattr(settings, 'MEDIA_HEADERS', [])
# self.media_headers = [
# (re.compile(r), headers) for r, headers in media_headers
# ]
#
import re
from aldryn_django.storage import S3MediaStorage
from django.conf import settings
from boto.s3.connection import (
SubdomainCallingFormat,
OrdinaryCallingFormat,
)
class PrivateS3MediaStorage(S3MediaStorage):
def __init__(self):
bucket_name = settings.AWS_MEDIA_STORAGE_BUCKET_NAME
if '.' in bucket_name:
calling_format = OrdinaryCallingFormat()
else:
calling_format = SubdomainCallingFormat()
# We cannot use a function call or a partial here. Instead, we have to
# create a subclass because django tries to recreate a new object by
# calling the __init__ of the returned object (with no arguments).
super(S3MediaStorage, self).__init__(
access_key=settings.AWS_MEDIA_ACCESS_KEY_ID,
secret_key=settings.AWS_MEDIA_SECRET_ACCESS_KEY,
bucket_name=bucket_name,
location=settings.AWS_MEDIA_BUCKET_PREFIX,
host=settings.AWS_MEDIA_STORAGE_HOST,
custom_domain=settings.AWS_MEDIA_DOMAIN,
calling_format=calling_format,
# Setting an ACL requires us to grant the user the PutObjectAcl
# permission as well, even if it matches the default bucket ACL.
# XXX: Ideally we would thus set it to `None`, but due to how
# easy_thumbnails works internally, that causes thumbnail
# generation to fail...
default_acl='private',
querystring_auth=True,
)
# MEDIA_HEADERS is a list of tuples containing a regular expression
# to match against a path, and a dictionary of HTTP headers to be
# returned with the resource identified by the path when it is
# requested.
# The headers are applied in the order they where declared, and
# processing stops at the first match.
# E.g.:
#
# MEDIA_HEADERS = [
# (r'media/cache/.*', {
# 'Cache-Control': 'max-age={}'.format(3600 * 24 * 365),
# })
# ]
#
media_headers = getattr(settings, 'MEDIA_HEADERS', [])
self.media_headers = [
(re.compile(r), headers) for r, headers in media_headers
]