| author | ymh <ymh.work@gmail.com> |
| Mon, 26 Jun 2017 16:05:47 +0200 | |
| changeset 88 | 2a861fed6bde |
| parent 60 | 42c07d428747 |
| child 97 | 69eaef18b01b |
| permissions | -rw-r--r-- |
| 24 | 1 |
""" |
2 |
Django settings for irinotes project. |
|
3 |
||
4 |
Generated by 'django-admin startproject' using Django 1.11.2. |
|
5 |
||
6 |
For more information on this file, see |
|
7 |
https://docs.djangoproject.com/en/1.11/topics/settings/ |
|
8 |
||
9 |
For the full list of settings and their values, see |
|
10 |
https://docs.djangoproject.com/en/1.11/ref/settings/ |
|
11 |
""" |
|
12 |
||
|
60
42c07d428747
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
13 |
import datetime |
| 24 | 14 |
import logging |
15 |
||
16 |
from decouple import Csv, config |
|
17 |
from dj_database_url import parse as db_url |
|
18 |
from unipath import Path |
|
19 |
||
20 |
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
|
21 |
BASE_DIR = Path(__file__).parent |
|
22 |
||
23 |
RUN_DIR = BASE_DIR.parent.child('run') |
|
24 |
||
25 |
STATIC_ROOT = config('STATIC_ROOT', default=RUN_DIR.child('web').child('static')) |
|
26 |
MEDIA_ROOT = config('MEDIA_ROOT', default=RUN_DIR.child('web').child('media')) |
|
27 |
||
28 |
# base url |
|
29 |
BASE_URL = config('BASE_URL', default='') |
|
30 |
||
31 |
# Quick-start development settings - unsuitable for production |
|
32 |
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ |
|
33 |
||
34 |
# SECURITY WARNING: keep the secret key used in production secret! |
|
35 |
SECRET_KEY = config('SECRET_KEY', '@povoyn_1_3dhfjktisno5l_0)_l1+m8$&mr8r2-srvd+m-58d') |
|
36 |
||
37 |
# SECURITY WARNING: don't run with debug turned on in production! |
|
38 |
DEBUG = config('DEBUG', default=True, cast=bool) |
|
39 |
||
40 |
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='', cast=Csv()) |
|
41 |
||
42 |
||
43 |
# Application definition |
|
44 |
||
45 |
INSTALLED_APPS = [ |
|
46 |
'django.contrib.admin', |
|
47 |
'django.contrib.auth', |
|
48 |
'django.contrib.contenttypes', |
|
49 |
'django.contrib.sessions', |
|
50 |
'django.contrib.messages', |
|
51 |
'django.contrib.staticfiles', |
|
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
52 |
'django.contrib.sites', |
| 31 | 53 |
'django_extensions', |
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
54 |
'irinotes', |
| 39 | 55 |
'corsheaders', |
| 31 | 56 |
'rest_framework', |
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
57 |
'rest_framework.authtoken', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
58 |
'allauth', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
59 |
'allauth.account', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
60 |
'rest_auth.registration', |
| 24 | 61 |
'colorful', |
62 |
'concurrency', |
|
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
63 |
'rest_auth', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
64 |
'notes', |
| 24 | 65 |
] |
66 |
||
67 |
MIDDLEWARE = [ |
|
68 |
'django.middleware.security.SecurityMiddleware', |
|
| 39 | 69 |
'corsheaders.middleware.CorsMiddleware', |
| 24 | 70 |
'django.contrib.sessions.middleware.SessionMiddleware', |
71 |
'django.middleware.common.CommonMiddleware', |
|
72 |
'django.middleware.csrf.CsrfViewMiddleware', |
|
73 |
'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
74 |
'django.contrib.messages.middleware.MessageMiddleware', |
|
75 |
'django.middleware.clickjacking.XFrameOptionsMiddleware', |
|
76 |
] |
|
77 |
||
78 |
ROOT_URLCONF = 'irinotes.urls' |
|
79 |
||
80 |
TEMPLATES = [ |
|
81 |
{ |
|
82 |
'BACKEND': 'django.template.backends.django.DjangoTemplates', |
|
83 |
'DIRS': [], |
|
84 |
'APP_DIRS': True, |
|
85 |
'OPTIONS': { |
|
86 |
'context_processors': [ |
|
87 |
'django.template.context_processors.debug', |
|
88 |
'django.template.context_processors.request', |
|
89 |
'django.contrib.auth.context_processors.auth', |
|
90 |
'django.contrib.messages.context_processors.messages', |
|
91 |
], |
|
92 |
}, |
|
93 |
}, |
|
94 |
] |
|
95 |
||
96 |
WSGI_APPLICATION = 'irinotes.wsgi.application' |
|
97 |
||
98 |
||
99 |
# Database |
|
100 |
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases |
|
101 |
||
102 |
DATABASES = { |
|
103 |
'default': config( |
|
104 |
'DATABASE_URL', |
|
105 |
default='sqlite:///' + RUN_DIR.child('db').child('db.sqlite3'), |
|
106 |
cast=db_url |
|
107 |
) |
|
108 |
} |
|
109 |
||
110 |
||
111 |
# Password validation |
|
112 |
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators |
|
113 |
||
114 |
AUTH_PASSWORD_VALIDATORS = [ |
|
115 |
{ |
|
116 |
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
|
117 |
}, |
|
118 |
{ |
|
119 |
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', |
|
120 |
}, |
|
121 |
{ |
|
122 |
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', |
|
123 |
}, |
|
124 |
{ |
|
125 |
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
|
126 |
}, |
|
127 |
] |
|
128 |
||
129 |
AUTH_USER_MODEL = 'notes.User' |
|
130 |
||
131 |
||
132 |
# Internationalization |
|
133 |
# https://docs.djangoproject.com/en/1.11/topics/i18n/ |
|
134 |
||
135 |
LANGUAGE_CODE = 'en-us' |
|
136 |
||
137 |
TIME_ZONE = 'UTC' |
|
138 |
||
139 |
USE_I18N = True |
|
140 |
||
141 |
USE_L10N = True |
|
142 |
||
143 |
USE_TZ = True |
|
144 |
||
145 |
||
146 |
# Static files (CSS, JavaScript, Images) |
|
147 |
# https://docs.djangoproject.com/en/1.11/howto/static-files/ |
|
148 |
||
149 |
STATIC_URL = config('STATIC_URL', default=BASE_URL + '/static/') |
|
150 |
||
151 |
# Logger |
|
152 |
||
153 |
LOG_FILE = config('LOG_FILE', default=RUN_DIR.child('log').child('log.txt')) |
|
154 |
LOG_LEVEL = config('LOG_LEVEL', default=logging.DEBUG, cast=lambda l: logging.getLevelName(l)) |
|
155 |
||
156 |
LOGGING = { |
|
157 |
'version': 1, |
|
158 |
'disable_existing_loggers': True, |
|
159 |
'filters': { |
|
160 |
'require_debug_false': { |
|
161 |
'()': 'django.utils.log.RequireDebugFalse' |
|
162 |
} |
|
163 |
}, |
|
164 |
'formatters' : { |
|
165 |
'simple' : { |
|
166 |
'format': "%(asctime)s - %(levelname)s : %(message)s", |
|
167 |
}, |
|
168 |
'semi-verbose': { |
|
169 |
'format': '%(levelname)s %(asctime)s %(module)s %(message)s' |
|
170 |
}, |
|
171 |
}, |
|
172 |
'handlers': { |
|
173 |
'mail_admins': { |
|
174 |
'level': 'ERROR', |
|
175 |
'filters': ['require_debug_false'], |
|
176 |
'class': 'django.utils.log.AdminEmailHandler' |
|
177 |
}, |
|
178 |
'stream_to_console': { |
|
179 |
'level': LOG_LEVEL, |
|
180 |
'class': 'logging.StreamHandler' |
|
181 |
}, |
|
182 |
'file': { |
|
183 |
'level': LOG_LEVEL, |
|
184 |
'class': 'logging.FileHandler', |
|
185 |
'filename': LOG_FILE, |
|
186 |
'formatter': 'semi-verbose', |
|
187 |
}, |
|
188 |
}, |
|
189 |
'loggers': { |
|
190 |
'django.request': { |
|
191 |
'handlers': ['file'], |
|
192 |
'level': LOG_LEVEL, |
|
193 |
'propagate': True, |
|
194 |
}, |
|
| 31 | 195 |
'django.db.backends': { |
196 |
'handlers': ['file'], |
|
197 |
'level': LOG_LEVEL, |
|
198 |
'propagate': True, |
|
199 |
}, |
|
| 24 | 200 |
'irinotes': { |
201 |
'handlers': ['file'], |
|
202 |
'level': LOG_LEVEL, |
|
203 |
'propagate': True, |
|
204 |
}, |
|
| 31 | 205 |
'notes': { |
206 |
'handlers': ['file'], |
|
207 |
'level': LOG_LEVEL, |
|
208 |
'propagate': True, |
|
209 |
}, |
|
| 24 | 210 |
} |
211 |
} |
|
| 31 | 212 |
|
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
213 |
SITE_ID = 1 |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
214 |
|
| 31 | 215 |
# Rest Framework configuration |
216 |
||
217 |
REST_FRAMEWORK = { |
|
218 |
# Use Django's standard `django.contrib.auth` permissions, |
|
219 |
# or allow read-only access for unauthenticated users. |
|
220 |
'DEFAULT_PERMISSION_CLASSES': [ |
|
221 |
'rest_framework.permissions.IsAuthenticated' |
|
222 |
], |
|
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
223 |
'DEFAULT_AUTHENTICATION_CLASSES': ( |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
224 |
'rest_framework_jwt.authentication.JSONWebTokenAuthentication', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
225 |
'rest_framework.authentication.SessionAuthentication', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
226 |
'rest_framework.authentication.BasicAuthentication', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
227 |
), |
| 31 | 228 |
'TEST_REQUEST_DEFAULT_FORMAT': 'json' |
229 |
} |
|
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
230 |
|
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
231 |
REST_USE_JWT = True |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
232 |
OLD_PASSWORD_FIELD_ENABLED = True |
| 39 | 233 |
|
|
60
42c07d428747
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
234 |
#JWT settings |
|
42c07d428747
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
235 |
JWT_AUTH = { |
|
42c07d428747
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
236 |
'JWT_ALLOW_REFRESH' : True, |
|
42c07d428747
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
237 |
'JWT_EXPIRATION_DELTA' : datetime.timedelta( |
|
42c07d428747
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
238 |
seconds=config('JWT_EXPIRATION_DELTA', 3600, cast=int) |
|
88
2a861fed6bde
Deauthenticate user if refresh was not possible (session expired or total delta reached)
ymh <ymh.work@gmail.com>
parents:
60
diff
changeset
|
239 |
), |
|
2a861fed6bde
Deauthenticate user if refresh was not possible (session expired or total delta reached)
ymh <ymh.work@gmail.com>
parents:
60
diff
changeset
|
240 |
'JWT_REFRESH_EXPIRATION_DELTA' : datetime.timedelta( |
|
2a861fed6bde
Deauthenticate user if refresh was not possible (session expired or total delta reached)
ymh <ymh.work@gmail.com>
parents:
60
diff
changeset
|
241 |
seconds=config('JWT_REFRESH_EXPIRATION_DELTA', 3600*24*7, cast=int) |
|
60
42c07d428747
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
242 |
) |
|
42c07d428747
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
243 |
} |
|
42c07d428747
on server, augment default token lifetime and add settings in .env to control it. Add the refresh endpoint
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
244 |
|
| 39 | 245 |
# CORS Headers |
246 |
CORS_ORIGIN_ALLOW_ALL = True |
|
247 |
CORS_URLS_REGEX = r'^/api/.*$' |