|
11 | 11 | """ |
12 | 12 |
|
13 | 13 | import os |
| 14 | +from datetime import datetime |
14 | 15 |
|
15 | 16 | import sentry_sdk |
16 | 17 | from factory.django import DjangoModelFactory |
17 | 18 | from rest_framework.serializers import ModelSerializer, Serializer |
18 | 19 | from sentry_sdk.integrations.django import DjangoIntegration |
| 20 | +from storages.backends.s3boto3 import S3Boto3Storage |
19 | 21 |
|
20 | 22 | # Analogous to RAILS_ENV, is one of {prod, staging, dev}. Defaults to dev. This default can |
21 | 23 | # be dangerous, but is worth it to avoid the hassle for developers setting the local ENV var |
|
67 | 69 | "frontend", |
68 | 70 | "django_extensions", |
69 | 71 | "django.contrib.postgres", |
| 72 | + "storages", |
70 | 73 | ] |
71 | 74 |
|
72 | 75 | SHELL_PLUS_SUBCLASSES_IMPORT = [ModelSerializer, Serializer, DjangoModelFactory] |
|
174 | 177 | AWS_S3_VERIFY = True |
175 | 178 | AWS_QUERYSTRING_AUTH = False # public bucket |
176 | 179 | DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" |
| 180 | +PROFILE_IMAGE_STORAGE = "csm_web.settings.ProfileImageStorage" |
177 | 181 |
|
178 | 182 | # Static files (CSS, JavaScript, Images) |
179 | 183 | # https://docs.djangoproject.com/en/2.1/howto/static-files/ |
180 | 184 |
|
181 | 185 | STATIC_URL = "/static/" |
| 186 | +# Do I need this? |
| 187 | +# MEDIA_URL = "/media/" |
| 188 | + |
| 189 | + |
| 190 | +# xTODO: make sure this actually works |
| 191 | +class ProfileImageStorage(S3Boto3Storage): |
| 192 | + bucket_name = "csm-web-profile-pictures" |
| 193 | + file_overwrite = False |
| 194 | + |
| 195 | + def get_accessed_time(self, name): |
| 196 | + # Implement logic to get the last accessed time |
| 197 | + return datetime.now() |
| 198 | + |
| 199 | + def get_created_time(self, name): |
| 200 | + # Implement logic to get the creation time |
| 201 | + return datetime.now() |
| 202 | + |
| 203 | + def path(self, name): |
| 204 | + # S3 does not support file paths |
| 205 | + raise NotImplementedError("This backend does not support absolute paths.") |
| 206 | + |
182 | 207 |
|
183 | 208 | if DJANGO_ENV in (PRODUCTION, STAGING): |
184 | 209 | # Enables compression and caching |
|
0 commit comments