1
1
import logging
2
2
3
- import sentry_sdk
4
-
5
- from sentry_sdk .integrations .django import DjangoIntegration
6
- from sentry_sdk .integrations .logging import LoggingIntegration
7
- from sentry_sdk .integrations .celery import CeleryIntegration
8
-
9
-
10
3
from .base import * # noqa
11
4
from .base import env
12
5
15
8
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
16
9
SECRET_KEY = env ("DJANGO_SECRET_KEY" )
17
10
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
18
- ALLOWED_HOSTS = env .list ("DJANGO_ALLOWED_HOSTS" , default = [ "django.codebuddies.org" ] )
11
+ ALLOWED_HOSTS = env .list ("DJANGO_ALLOWED_HOSTS" )
19
12
20
13
# DATABASES
21
14
# ------------------------------------------------------------------------------
22
15
DATABASES ["default" ] = env .db ("DATABASE_URL" ) # noqa F405
23
16
DATABASES ["default" ]["ATOMIC_REQUESTS" ] = True # noqa F405
24
17
DATABASES ["default" ]["CONN_MAX_AGE" ] = env .int ("CONN_MAX_AGE" , default = 60 ) # noqa F405
25
18
26
- # CACHES
27
- # ------------------------------------------------------------------------------
28
- CACHES = {
29
- "default" : {
30
- "BACKEND" : "django_redis.cache.RedisCache" ,
31
- "LOCATION" : env ("REDIS_URL" ),
32
- "OPTIONS" : {
33
- "CLIENT_CLASS" : "django_redis.client.DefaultClient" ,
34
- # Mimicing memcache behavior.
35
- # http://niwinz.github.io/django-redis/latest/#_memcached_exceptions_behavior
36
- "IGNORE_EXCEPTIONS" : True ,
37
- },
38
- }
39
- }
40
-
41
19
# SECURITY
42
20
# ------------------------------------------------------------------------------
43
21
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
63
41
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF" , default = True
64
42
)
65
43
66
- # STORAGES
67
- # ------------------------------------------------------------------------------
68
- # https://django-storages.readthedocs.io/en/latest/#installation
69
- INSTALLED_APPS += ["storages" ] # noqa F405
70
- # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
71
- AWS_ACCESS_KEY_ID = env ("DJANGO_AWS_ACCESS_KEY_ID" )
72
- # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
73
- AWS_SECRET_ACCESS_KEY = env ("DJANGO_AWS_SECRET_ACCESS_KEY" )
74
- # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
75
- AWS_STORAGE_BUCKET_NAME = env ("DJANGO_AWS_STORAGE_BUCKET_NAME" )
76
- # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
77
- AWS_QUERYSTRING_AUTH = False
78
- # DO NOT change these unless you know what you're doing.
79
- _AWS_EXPIRY = 60 * 60 * 24 * 7
80
- # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
81
- AWS_S3_OBJECT_PARAMETERS = {
82
- "CacheControl" : f"max-age={ _AWS_EXPIRY } , s-maxage={ _AWS_EXPIRY } , must-revalidate"
83
- }
84
- # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
85
- AWS_DEFAULT_ACL = None
86
- # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
87
- AWS_S3_REGION_NAME = env ("DJANGO_AWS_S3_REGION_NAME" , default = None )
88
- # STATIC
89
- # ------------------------
90
- STATICFILES_STORAGE = "config.settings.production.StaticRootS3Boto3Storage"
91
- STATIC_URL = f"https://{ AWS_STORAGE_BUCKET_NAME } .s3.amazonaws.com/static/"
92
- # MEDIA
93
- # ------------------------------------------------------------------------------
94
- # region http://stackoverflow.com/questions/10390244/
95
- # Full-fledge class: https://stackoverflow.com/a/18046120/104731
96
- from storages .backends .s3boto3 import S3Boto3Storage # noqa E402
97
-
98
-
99
- class StaticRootS3Boto3Storage (S3Boto3Storage ):
100
- location = "static"
101
- default_acl = "public-read"
102
-
103
-
104
- class MediaRootS3Boto3Storage (S3Boto3Storage ):
105
- location = "media"
106
- file_overwrite = False
107
-
108
-
109
- # endregion
110
- DEFAULT_FILE_STORAGE = "config.settings.production.MediaRootS3Boto3Storage"
111
- MEDIA_URL = f"https://{ AWS_STORAGE_BUCKET_NAME } .s3.amazonaws.com/media/"
112
-
113
44
# TEMPLATES
114
45
# ------------------------------------------------------------------------------
115
46
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
@@ -141,24 +72,6 @@ class MediaRootS3Boto3Storage(S3Boto3Storage):
141
72
# Django Admin URL regex.
142
73
ADMIN_URL = env ("DJANGO_ADMIN_URL" )
143
74
144
- # Anymail (Mailgun)
145
- # ------------------------------------------------------------------------------
146
- # https://anymail.readthedocs.io/en/stable/installation/#installing-anymail
147
- INSTALLED_APPS += ["anymail" ] # noqa F405
148
- EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
149
- # https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference
150
- ANYMAIL = {
151
- "MAILGUN_API_KEY" : env ("MAILGUN_API_KEY" ),
152
- "MAILGUN_SENDER_DOMAIN" : env ("MAILGUN_DOMAIN" ),
153
- "MAILGUN_API_URL" : env ("MAILGUN_API_URL" , default = "https://api.mailgun.net/v3" ),
154
- }
155
-
156
- # Collectfast
157
- # ------------------------------------------------------------------------------
158
- # https://github.com/antonagestam/collectfast#installation
159
- INSTALLED_APPS = ["collectfast" ] + INSTALLED_APPS # noqa F405
160
- AWS_PRELOAD_METADATA = True
161
-
162
75
# LOGGING
163
76
# ------------------------------------------------------------------------------
164
77
# https://docs.djangoproject.com/en/dev/ref/settings/#logging
@@ -189,7 +102,6 @@ class MediaRootS3Boto3Storage(S3Boto3Storage):
189
102
"propagate" : False ,
190
103
},
191
104
# Errors logged by the SDK itself
192
- "sentry_sdk" : {"level" : "ERROR" , "handlers" : ["console" ], "propagate" : False },
193
105
"django.security.DisallowedHost" : {
194
106
"level" : "ERROR" ,
195
107
"handlers" : ["console" ],
@@ -198,19 +110,5 @@ class MediaRootS3Boto3Storage(S3Boto3Storage):
198
110
},
199
111
}
200
112
201
- # Sentry
202
- # ------------------------------------------------------------------------------
203
- SENTRY_DSN = env ("SENTRY_DSN" )
204
- SENTRY_LOG_LEVEL = env .int ("DJANGO_SENTRY_LOG_LEVEL" , logging .INFO )
205
-
206
- sentry_logging = LoggingIntegration (
207
- level = SENTRY_LOG_LEVEL , # Capture info and above as breadcrumbs
208
- event_level = logging .ERROR , # Send errors as events
209
- )
210
- sentry_sdk .init (
211
- dsn = SENTRY_DSN ,
212
- integrations = [sentry_logging , DjangoIntegration (), CeleryIntegration ()],
213
- )
214
-
215
113
# Your stuff...
216
114
# ------------------------------------------------------------------------------
0 commit comments