Skip to content

Commit 8a14bc0

Browse files
authored
update django-storages conf (#1632)
* update django-storages conf * remove aws headers * switch to headers argument * Revert "switch to headers argument" This reverts commit 7236495.
1 parent 0dae9bc commit 8a14bc0

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

openstax/custom_storages.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

openstax/settings/base.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,42 @@
104104
AWS_STORAGE_DIR = os.getenv('AWS_STORAGE_DIR', 'oscms-test')
105105
AWS_S3_CUSTOM_DOMAIN = os.getenv('AWS_S3_CUSTOM_DOMAIN', 'assets.openstax.org')
106106
AWS_DEFAULT_ACL = 'public-read'
107-
AWS_HEADERS = {'Access-Control-Allow-Origin': '*'}
108107

109108
################
110109
# Static/Media #
111110
################
112-
113-
# Use local storage for media and static files in local environment
114111
if DEBUG or ENVIRONMENT == 'test':
115-
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
112+
# Local development storage configuration
113+
STORAGES = {
114+
"default": {
115+
"BACKEND": "django.core.files.storage.FileSystemStorage",
116+
},
117+
"staticfiles": {
118+
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
119+
},
120+
}
116121
else:
117122
# S3 media storage using custom backend
118123
MEDIAFILES_LOCATION = '{}/media'.format(AWS_STORAGE_DIR)
119124
MEDIA_URL = "https://%s/%s/media/" % (AWS_S3_CUSTOM_DOMAIN, AWS_STORAGE_DIR)
120-
DEFAULT_FILE_STORAGE = 'openstax.custom_storages.MediaStorage'
121-
122-
# Static files are stored on the server and served by nginx
123-
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
125+
126+
STORAGES = {
127+
"default": {
128+
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
129+
"OPTIONS": {
130+
"bucket_name": AWS_STORAGE_BUCKET_NAME,
131+
"custom_domain": AWS_S3_CUSTOM_DOMAIN,
132+
"default_acl": AWS_DEFAULT_ACL,
133+
"location": MEDIAFILES_LOCATION,
134+
"file_overwrite": False,
135+
"querystring_auth": False,
136+
"use_ssl": True,
137+
},
138+
},
139+
"staticfiles": {
140+
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
141+
},
142+
}
124143

125144
# Absolute path to the directory static files should be collected to.
126145
# Don't put anything in this directory yourself; store your static files

openstax/settings/docker.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@
5757
# Media #
5858
#################
5959
# locally, we want to use local storage for uploaded (media) files
60-
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
61-
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
60+
STORAGES = {
61+
"default": {
62+
"BACKEND": "django.core.files.storage.FileSystemStorage",
63+
},
64+
"staticfiles": {
65+
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
66+
},
67+
}
6268

6369
#################
6470
# CORS #

openstax/settings/test.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
DEBUG = True
44
ENVIRONMENT = 'test'
55

6-
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
7-
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
6+
STORAGES = {
7+
"default": {
8+
"BACKEND": "django.core.files.storage.FileSystemStorage",
9+
},
10+
"staticfiles": {
11+
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
12+
},
13+
}
814

915
SALESFORCE = {
1016
'username': '[email protected]',

0 commit comments

Comments
 (0)