· 5 years ago · Jan 19, 2020, 12:44 PM
1import os
2import django_heroku
3import sys
4
5import dj_database_url
6
7BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
8# Also add ../../apps to python path
9sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
10
11# =============================================================================
12# # Django
13# =============================================================================
14ALLOWED_HOSTS = ['*']
15USE_X_FORWARDED_HOST = True
16
17SITE_ID = 1
18
19SITE_DOMAIN = os.environ.get('SITE_DOMAIN', 'http://localhost')
20
21THIRD_PARTY_APPS = (
22 'django.contrib.sites',
23 'django.contrib.admin',
24 'django.contrib.auth',
25 'django.contrib.contenttypes',
26 'django.contrib.sessions',
27 'django.contrib.messages',
28 'django.contrib.staticfiles',
29 'django.contrib.postgres',
30 'whitenoise',
31 'rest_framework',
32 'django_heroku',
33
34 # Sorl Thumbnail'
35 'sorl.thumbnail',
36 'django_extensions',
37
38)
39OUR_APPS = (
40 'monster',
41 'attacks',
42 'bindings',
43 'players',
44)
45INSTALLED_APPS = THIRD_PARTY_APPS + OUR_APPS
46
47MIDDLEWARE = (
48 'whitenoise.middleware.WhiteNoiseMiddleware',
49 'django.middleware.security.SecurityMiddleware',
50 'django.contrib.sessions.middleware.SessionMiddleware',
51 'django.middleware.common.CommonMiddleware',
52 'django.middleware.csrf.CsrfViewMiddleware',
53 'django.contrib.auth.middleware.AuthenticationMiddleware',
54 'django.contrib.messages.middleware.MessageMiddleware',
55 'django.middleware.clickjacking.XFrameOptionsMiddleware',
56)
57
58ROOT_URLCONF = 'urls'
59
60TEMPLATES = [
61 {
62 'BACKEND': 'django.template.backends.django.DjangoTemplates',
63 'DIRS': [
64 os.path.join(BASE_DIR, 'templates'),
65 ],
66 'APP_DIRS': True,
67 'OPTIONS': {
68 'context_processors': [
69 'django.template.context_processors.debug',
70 'django.template.context_processors.request',
71 'django.template.context_processors.static',
72 'django.template.context_processors.media',
73 'django.contrib.auth.context_processors.auth',
74 'django.contrib.messages.context_processors.messages',
75 ],
76 },
77 },
78]
79
80WSGI_APPLICATION = 'wsgi.application'
81LANGUAGE_CODE = 'en-us'
82TIME_ZONE = 'UTC'
83USE_I18N = True
84USE_L10N = True
85USE_TZ = True
86SECRET_KEY = os.environ.get("SECRET_KEY", '{{ secret_key }}')
87
88EMAIL_BACKEND = os.environ.get('EMAIL_BACKEND', 'django.core.mail.backends.console.EmailBackend')
89
90DEFAULT_FROM_EMAIL = 'Do Not Reply <donotreply@blank.com>'
91SERVER_EMAIL = 'Do Not Reply <donotreply@blank.com>'
92
93LOGIN_REDIRECT_URL = '/'
94
95# =============================================================================
96# # Wagtail
97# =============================================================================
98WAGTAIL_SITE_NAME = 'Monsta Dex'
99
100# =============================================================================
101# Debugging
102# =============================================================================
103DEBUG = os.environ.get('DEBUG', True)
104
105# =============================================================================
106# Database
107# =============================================================================
108DATABASES = {'default': {}}
109
110db_from_env = dj_database_url.config()
111if db_from_env:
112 DATABASES['default'].update(db_from_env)
113else:
114 DATABASES = {
115 'default': {
116 'ENGINE': 'django.db.backends.sqlite3',
117 'NAME': 'monstadex.db',
118 }
119 }
120
121# # =============================================================================
122# # SSL
123# # =============================================================================
124# if os.environ.get('USE_SSL'):
125# SECURE_SSL_REDIRECT = True
126# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
127# else:
128# # Allows us to use with django-oauth-toolkit on localhost sans https
129# SESSION_COOKIE_SECURE = False
130
131
132# =============================================================================
133# DRF
134# =============================================================================
135REST_FRAMEWORK = {
136 'DEFAULT_AUTHENTICATION_CLASSES': (
137 'rest_framework.authentication.SessionAuthentication',
138 ),
139 'DEFAULT_PERMISSION_CLASSES': (
140 'rest_framework.permissions.IsAuthenticated',
141 ),
142 'DATETIME_INPUT_FORMATS': (
143 'iso-8601',
144 '%B %d, %Y',
145 )
146}
147
148# =============================================================================
149# OAuth
150# =============================================================================
151CORS_ORIGIN_ALLOW_ALL = True
152
153if not DEBUG:
154 assert not CORS_ORIGIN_ALLOW_ALL, "Disable CORS_ORIGIN_ALLOW_ALL if we're not in DEBUG mode"
155
156# =============================================================================
157# Storage
158# =============================================================================
159STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
160STATIC_URL = '/static/'
161STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
162STATICFILES_FINDERS = (
163 'django.contrib.staticfiles.finders.FileSystemFinder',
164 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
165)
166STATICFILES_DIRS = (
167 os.path.join(BASE_DIR, '../src/static'),
168)
169MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
170MEDIA_URL = '/media/'
171
172# =============================================================================
173# Debug
174# =============================================================================
175if DEBUG:
176 INSTALLED_APPS += ('debug_toolbar',)
177 MIDDLEWARE = (
178 'debug_toolbar.middleware.DebugToolbarMiddleware',
179 'querycount.middleware.QueryCountMiddleware',
180 'whitenoise.middleware.WhiteNoiseMiddleware',
181
182 ) + MIDDLEWARE # we want Debug Middleware at the top
183
184 INTERNAL_IPS = ['127.0.0.1']
185
186 import socket
187
188 try:
189 INTERNAL_IPS.append(socket.gethostbyname(socket.gethostname())[:-1])
190 except socket.gaierror:
191 pass
192
193 QUERYCOUNT = {
194 'IGNORE_REQUEST_PATTERNS': [
195 r'^/admin/',
196 r'^/static/',
197 ]
198 }
199
200 DEBUG_TOOLBAR_CONFIG = {
201 "SHOW_TOOLBAR_CALLBACK": lambda request: True
202 }
203
204
205django_heroku.settings(locals())