-
Notifications
You must be signed in to change notification settings - Fork 17
/
settings.py
216 lines (179 loc) · 6.31 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
127
128
129
130
131
132
133
134
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Django settings for eggtimer project.
import os
from dotenv import load_dotenv
from django.utils.dateparse import parse_datetime
import dj_database_url
from email.utils import formataddr
load_dotenv()
HOME_DIR = os.path.expanduser("~")
BASE_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.pardir))
ADMINS = (
(os.environ.get('ADMIN_NAME', 'admin'), os.environ.get('ADMIN_EMAIL', 'example@example.com')),
)
# Export a secret value in production; for local development, the default is good enough
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY',
'psu&83=i(4wgd@9*go=nps9=1rw#9b_w6psy4mp6yoxqv1i5g')
# Use env setting if available, otherwise make debug false
DEBUG = bool(int(os.environ.get('DJANGO_DEBUG', '0')))
ALLOWED_HOSTS = [
'eggtimer.jessamynsmith.ca',
'eggtimer.herokuapp.com',
'165.227.42.38',
'localhost',
'127.0.0.1'
]
CORS_ORIGIN_ALLOW_ALL = True
SECURE_SSL_REDIRECT = bool(int(os.environ.get('DJANGO_ENABLE_SSL', '1')))
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'custom_user',
'settings_context_processor',
'gunicorn',
'corsheaders',
'allauth',
'allauth.account',
'allauth.socialaccount',
# TODO re-enable social accounts once ssl is set up
# 'allauth.socialaccount.providers.facebook',
# 'allauth.socialaccount.providers.github',
'rest_framework',
'rest_framework.authtoken',
'floppyforms',
'bootstrapform',
'timezone_field',
'periods',
]
MIDDLEWARE_CLASSES = (
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'periods.middleware.AddAuthTokenMiddleware',
)
ROOT_URLCONF = 'eggtimer.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'eggtimer', 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
"django.contrib.auth.context_processors.auth",
'django.template.context_processors.debug',
'django.template.context_processors.request',
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"settings_context_processor.context_processors.settings",
],
'debug': DEBUG,
},
},
]
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'eggtimer.wsgi.application'
# Parse database configuration from DATABASE_URL environment variable
DATABASES = {
'default': dj_database_url.config(
default="sqlite:///%s" % os.path.join(HOME_DIR, 'eggtimer', 'eggtimer.sqlite')
)
}
SITE_ID = 1
# https://docs.djangoproject.com/en/1.8/topics/i18n/
TIME_ZONE = 'UTC'
LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True
USE_TZ = True
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(BASE_DIR, 'bower_components'),
os.path.join(BASE_DIR, 'eggtimer', 'static'),
)
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend"
)
# auth and allauth
AUTH_USER_MODEL = 'periods.User'
LOGIN_REDIRECT_URL = '/calendar/'
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_LOGOUT_ON_GET = True
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
'facebook': {
'SCOPE': ['email'],
'METHOD': 'oauth2',
}
}
ACCOUNT_ACTIVATION_DAYS = 14
DEFAULT_FROM_EMAIL = formataddr(ADMINS[0])
REPLY_TO = (
os.environ.get('REPLY_TO_EMAIL', 'example@example.com'),
)
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_PORT = 587
EMAIL_HOST_USER = "apikey"
EMAIL_HOST_PASSWORD = os.environ.get('SENDGRID_API_KEY')
EMAIL_USE_TLS = True
if not EMAIL_HOST_PASSWORD:
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = os.path.join(HOME_DIR, 'eggtimer', 'emails')
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',)
}
# US Navy API is used for moon phases
# http://aa.usno.navy.mil/data/docs/api.php#phase
MOON_PHASE_URL = 'http://api.usno.navy.mil'
API_DATE_FORMAT = '%Y-%m-%d'
US_DATE_FORMAT = '%-m/%-d/%Y'
# TODO maybe this could be a django plugin?
DEPLOY_DATE = parse_datetime(os.environ.get('DEPLOY_DATE', ''))
VERSION = '0.6'
TEMPLATE_VISIBLE_SETTINGS = ['DEPLOY_DATE', 'VERSION', 'ADMINS']
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
# if DEBUG:
# INSTALLED_APPS.extend([
# 'django_extensions',
# ])