production.py 5.6 KB
Newer Older
Thom Wiggers's avatar
Thom Wiggers committed
1
"""
2
Django production settings for thaliawebsite project.
Thom Wiggers's avatar
Thom Wiggers committed
3

4
5
6
7
Many of these settings override settings from settings.py.

This file is loaded by __init__.py if the environment variable
`DJANGO_PRODUCTION` is set.
Thom Wiggers's avatar
Thom Wiggers committed
8
9

See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
Thom Wiggers's avatar
Thom Wiggers committed
10
11
12
"""

import os
13
14
15
16

from . import settings

INSTALLED_APPS = settings.INSTALLED_APPS
17
INSTALLED_APPS.append('raven.contrib.django.raven_compat')
18

Thom Wiggers's avatar
Thom Wiggers committed
19
20
21
22
23
24
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.abspath(os.path.join(
    os.path.dirname(os.path.abspath(__file__)),
    '..', '..'))


Thom Wiggers's avatar
Thom Wiggers committed
25
26
27
28
29
30
31
32
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get(
    'DJANGO_SECRET',
    '#o-0d1q5&^&06tn@8pr1f(n3$crafd++^%sacao7hj*ea@c)^t')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG') == 'True'

33
34
if 'DJANGO_HOSTS' in os.environ:
    ALLOWED_HOSTS = os.environ.get('DJANGO_HOSTS').split(',')
Thom Wiggers's avatar
Thom Wiggers committed
35

Thom Wiggers's avatar
Thom Wiggers committed
36
# Database settings
Thom Wiggers's avatar
Thom Wiggers committed
37
38
39
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
40
        'USER': os.environ.get('POSTGRES_USER', 'postgres'),
41
        'PASSWORD': os.environ.get('POSTGRES_PASSWORD', ''),
42
        'NAME': os.environ.get('POSTGRES_DB'),
Thom Wiggers's avatar
Thom Wiggers committed
43
44
45
46
        'HOST': os.environ.get('DJANGO_POSTGRES_HOST'),
        'PORT': 5432,
    }
}
Thom Wiggers's avatar
Thom Wiggers committed
47
48
49
50

# Persistent database connections
CONN_MAX_AGE = '60'

Thom Wiggers's avatar
Thom Wiggers committed
51
52
53
54
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/

# Where to store uploaded files
Thom Wiggers's avatar
Thom Wiggers committed
55
MEDIA_ROOT = '/concrexit/media'
Thom Wiggers's avatar
Thom Wiggers committed
56
57
MEDIA_URL = '/media/'  # Public is included by the db fields

58
59
if not settings.DEBUG:
    SENDFILE_BACKEND = 'sendfile.backends.nginx'
60
61
SENDFILE_URL = '/media/'
SENDFILE_ROOT = '/concrexit/media/'
Thom Wiggers's avatar
Thom Wiggers committed
62
63

STATIC_URL = '/static/'
Thom Wiggers's avatar
Thom Wiggers committed
64
STATIC_ROOT = '/concrexit/static'
Thom Wiggers's avatar
Thom Wiggers committed
65

Thom Wiggers's avatar
Thom Wiggers committed
66
67
if not DEBUG:
    COMPRESS_OFFLINE = True
68
69
70
71
72
73
74
75

PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.Argon2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
    'django.contrib.auth.hashers.BCryptPasswordHasher',
]
Thom Wiggers's avatar
Thom Wiggers committed
76
77

WIKI_API_KEY = os.environ.get('WIKI_API_KEY', 'changeme')
Thom Wiggers's avatar
Thom Wiggers committed
78
MIGRATION_KEY = os.environ.get('MIGRATION_KEY')
79
PUSH_NOTIFICATIONS_API_KEY = os.environ.get('PUSH_NOTIFICATIONS_API_KEY', '')
80
MAILINGLIST_API_SECRET = os.environ.get('MAILINGLIST_API_SECRET', '')
81
MEMBERS_SENTRY_API_SECRET = os.environ.get('MEMBERS_SENTRY_API_SECRET', '')
Thom Wiggers's avatar
Thom Wiggers committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

if os.environ.get('DJANGO_SSLONLY'):
    SECURE_SSL_REDIRECT = True
    SESSION_COOKIE_SECURE = True
    CSRF_COOKIE_SECURE = True

# Use caching template loader
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.template.context_processors.media',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'partners.context_processors.showcased_partners',
101
                'announcements.context_processors.announcements',
Thom Wiggers's avatar
Thom Wiggers committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
            ],
            'loaders': [
                ('django.template.loaders.cached.Loader', [
                    'django.template.loaders.filesystem.Loader',
                    'django.template.loaders.app_directories.Loader',
                ]),
            ],
        },
    },
]

# ADMINS
ADMINS = [('Technicie', 'www@thalia.nu')]

# Email backend
if os.environ.get('DJANGO_EMAIL_HOST'):
    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
    EMAIL_HOST = os.environ['DJANGO_EMAIL_HOST']
    EMAIL_PORT = os.environ['DJANGO_EMAIL_PORT']
    EMAIL_HOST_USER = os.environ.get('DJANGO_EMAIL_HOST_USER')
    EMAIL_HOST_PASSWORD = os.environ.get('DJANGO_EMAIL_HOST_PASSWORD')
    EMAIL_USE_TLS = os.environ.get('DJANGO_EMAIL_USE_TLS', False) == 'True'
    EMAIL_USE_SSL = os.environ.get('DJANGO_EMAIL_USE_SSL', False) == 'True'
    EMAIL_TIMEOUT = 10

127
# Celery settings
128
CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL')
129
CELERY_ENABLED = True
130

Thom Wiggers's avatar
Thom Wiggers committed
131
132
133
134
# Secure headers
X_FRAME_OPTIONS = 'DENY'
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        },
    },
    'root': {
        'level': 'WARNING',
        'handlers': ['sentry'],
    },
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s '
                      '%(process)d %(thread)d %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        },
        'sentry': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'raven.contrib.django.raven_compat.'
                     'handlers.SentryHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
        },
        'raven': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
        'sentry.errors': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
    },
}


RAVEN_CONFIG = {
    'dsn': os.environ.get('SENTRY_DSN'),
    'release': os.environ.get('SOURCE_COMMIT'),
189
}