| author | salimr <riwad.salim@yahoo.fr> |
| Mon, 08 Oct 2018 04:09:19 +0200 | |
| changeset 161 | a642639dbc07 |
| parent 142 | 56850f5c73f6 |
| child 178 | 89d8432aad9f |
| 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 |
||
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
16 |
from corsheaders.defaults import default_headers |
| 24 | 17 |
from decouple import Csv, config |
18 |
from dj_database_url import parse as db_url |
|
19 |
from unipath import Path |
|
20 |
||
21 |
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
|
22 |
BASE_DIR = Path(__file__).parent |
|
23 |
||
24 |
RUN_DIR = BASE_DIR.parent.child('run') |
|
25 |
||
26 |
STATIC_ROOT = config('STATIC_ROOT', default=RUN_DIR.child('web').child('static')) |
|
27 |
MEDIA_ROOT = config('MEDIA_ROOT', default=RUN_DIR.child('web').child('media')) |
|
28 |
||
29 |
# base url |
|
30 |
BASE_URL = config('BASE_URL', default='') |
|
31 |
||
32 |
# Quick-start development settings - unsuitable for production |
|
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', |
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
54 |
'django_filters', |
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
55 |
'irinotes', |
| 39 | 56 |
'corsheaders', |
| 31 | 57 |
'rest_framework', |
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
58 |
'rest_framework.authtoken', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
59 |
'allauth', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
60 |
'allauth.account', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
61 |
'rest_auth.registration', |
| 24 | 62 |
'colorful', |
63 |
'concurrency', |
|
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
64 |
'rest_auth', |
| 126 | 65 |
'auditlog', |
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
66 |
'notes', |
| 142 | 67 |
'protocols' |
| 24 | 68 |
] |
69 |
||
70 |
MIDDLEWARE = [ |
|
71 |
'django.middleware.security.SecurityMiddleware', |
|
| 39 | 72 |
'corsheaders.middleware.CorsMiddleware', |
| 24 | 73 |
'django.contrib.sessions.middleware.SessionMiddleware', |
74 |
'django.middleware.common.CommonMiddleware', |
|
75 |
'django.middleware.csrf.CsrfViewMiddleware', |
|
76 |
'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
77 |
'django.contrib.messages.middleware.MessageMiddleware', |
|
78 |
'django.middleware.clickjacking.XFrameOptionsMiddleware', |
|
|
128
34a75bd8d0b9
add filter on session and node list to recover specific objects
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
79 |
'notes.middlewares.JWTAuthenticationMiddleware', |
| 126 | 80 |
'auditlog.middleware.AuditlogMiddleware' |
| 24 | 81 |
] |
82 |
||
83 |
ROOT_URLCONF = 'irinotes.urls' |
|
84 |
||
85 |
TEMPLATES = [ |
|
86 |
{ |
|
87 |
'BACKEND': 'django.template.backends.django.DjangoTemplates', |
|
88 |
'DIRS': [], |
|
89 |
'APP_DIRS': True, |
|
90 |
'OPTIONS': { |
|
91 |
'context_processors': [ |
|
92 |
'django.template.context_processors.debug', |
|
93 |
'django.template.context_processors.request', |
|
94 |
'django.contrib.auth.context_processors.auth', |
|
95 |
'django.contrib.messages.context_processors.messages', |
|
96 |
], |
|
97 |
}, |
|
98 |
}, |
|
99 |
] |
|
100 |
||
101 |
WSGI_APPLICATION = 'irinotes.wsgi.application' |
|
102 |
||
103 |
||
104 |
# Database |
|
| 142 | 105 |
TEST_DATABASE_NAME = config('TEST_DATABASE_NAME', None) |
| 24 | 106 |
|
107 |
DATABASES = { |
|
| 142 | 108 |
'default': { **config( |
| 24 | 109 |
'DATABASE_URL', |
110 |
default='sqlite:///' + RUN_DIR.child('db').child('db.sqlite3'), |
|
111 |
cast=db_url |
|
| 142 | 112 |
), |
113 |
**({ |
|
114 |
'TEST': { |
|
115 |
'NAME': TEST_DATABASE_NAME |
|
116 |
} |
|
117 |
} if TEST_DATABASE_NAME else {}) |
|
118 |
} |
|
| 24 | 119 |
} |
120 |
||
121 |
||
122 |
# Password validation |
|
123 |
||
124 |
AUTH_PASSWORD_VALIDATORS = [ |
|
125 |
{ |
|
126 |
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
|
127 |
}, |
|
128 |
{ |
|
129 |
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', |
|
130 |
}, |
|
131 |
{ |
|
132 |
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', |
|
133 |
}, |
|
134 |
{ |
|
135 |
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
|
136 |
}, |
|
137 |
] |
|
138 |
||
139 |
AUTH_USER_MODEL = 'notes.User' |
|
140 |
||
141 |
||
142 |
# Internationalization |
|
143 |
# https://docs.djangoproject.com/en/1.11/topics/i18n/ |
|
144 |
||
145 |
LANGUAGE_CODE = 'en-us' |
|
146 |
||
147 |
TIME_ZONE = 'UTC' |
|
148 |
||
149 |
USE_I18N = True |
|
150 |
||
151 |
USE_L10N = True |
|
152 |
||
153 |
USE_TZ = True |
|
154 |
||
155 |
||
156 |
# Static files (CSS, JavaScript, Images) |
|
157 |
# https://docs.djangoproject.com/en/1.11/howto/static-files/ |
|
158 |
||
159 |
STATIC_URL = config('STATIC_URL', default=BASE_URL + '/static/') |
|
160 |
||
161 |
# Logger |
|
162 |
||
163 |
LOG_FILE = config('LOG_FILE', default=RUN_DIR.child('log').child('log.txt')) |
|
164 |
LOG_LEVEL = config('LOG_LEVEL', default=logging.DEBUG, cast=lambda l: logging.getLevelName(l)) |
|
165 |
||
166 |
LOGGING = { |
|
167 |
'version': 1, |
|
168 |
'disable_existing_loggers': True, |
|
169 |
'filters': { |
|
170 |
'require_debug_false': { |
|
171 |
'()': 'django.utils.log.RequireDebugFalse' |
|
172 |
} |
|
173 |
}, |
|
174 |
'formatters' : { |
|
175 |
'simple' : { |
|
176 |
'format': "%(asctime)s - %(levelname)s : %(message)s", |
|
177 |
}, |
|
178 |
'semi-verbose': { |
|
179 |
'format': '%(levelname)s %(asctime)s %(module)s %(message)s' |
|
180 |
}, |
|
181 |
}, |
|
182 |
'handlers': { |
|
183 |
'mail_admins': { |
|
184 |
'level': 'ERROR', |
|
185 |
'filters': ['require_debug_false'], |
|
186 |
'class': 'django.utils.log.AdminEmailHandler' |
|
187 |
}, |
|
188 |
'stream_to_console': { |
|
189 |
'level': LOG_LEVEL, |
|
190 |
'class': 'logging.StreamHandler' |
|
191 |
}, |
|
192 |
'file': { |
|
193 |
'level': LOG_LEVEL, |
|
194 |
'class': 'logging.FileHandler', |
|
195 |
'filename': LOG_FILE, |
|
196 |
'formatter': 'semi-verbose', |
|
197 |
}, |
|
198 |
}, |
|
199 |
'loggers': { |
|
200 |
'django.request': { |
|
201 |
'handlers': ['file'], |
|
202 |
'level': LOG_LEVEL, |
|
203 |
'propagate': True, |
|
204 |
}, |
|
|
131
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
205 |
# 'django.db.backends': { |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
206 |
# 'handlers': ['file'], |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
207 |
# 'level': LOG_LEVEL, |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
208 |
# 'propagate': True, |
|
adad5563603c
add personal group, default_group to users and add group info to session on backend
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
209 |
# }, |
| 24 | 210 |
'irinotes': { |
211 |
'handlers': ['file'], |
|
212 |
'level': LOG_LEVEL, |
|
213 |
'propagate': True, |
|
214 |
}, |
|
| 31 | 215 |
'notes': { |
216 |
'handlers': ['file'], |
|
217 |
'level': LOG_LEVEL, |
|
218 |
'propagate': True, |
|
219 |
}, |
|
| 142 | 220 |
'protocols': { |
221 |
'handlers': ['file'], |
|
222 |
'level': LOG_LEVEL, |
|
223 |
'propagate': True, |
|
224 |
}, |
|
| 24 | 225 |
} |
226 |
} |
|
| 31 | 227 |
|
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
228 |
SITE_ID = 1 |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
229 |
|
| 31 | 230 |
# Rest Framework configuration |
231 |
||
232 |
REST_FRAMEWORK = { |
|
233 |
# Use Django's standard `django.contrib.auth` permissions, |
|
234 |
# or allow read-only access for unauthenticated users. |
|
235 |
'DEFAULT_PERMISSION_CLASSES': [ |
|
236 |
'rest_framework.permissions.IsAuthenticated' |
|
237 |
], |
|
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
238 |
'DEFAULT_AUTHENTICATION_CLASSES': ( |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
239 |
'rest_framework_jwt.authentication.JSONWebTokenAuthentication', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
240 |
'rest_framework.authentication.SessionAuthentication', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
241 |
'rest_framework.authentication.BasicAuthentication', |
|
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
242 |
), |
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
243 |
'TEST_REQUEST_DEFAULT_FORMAT': 'json', |
| 142 | 244 |
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', |
|
119
8ff8e2aee0f9
add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents:
97
diff
changeset
|
245 |
'PAGE_SIZE': 100 |
| 31 | 246 |
} |
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
247 |
|
|
133
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
248 |
# Rest auth settings |
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
249 |
REST_USE_JWT = True |
|
133
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
250 |
REST_AUTH_SERIALIZERS = { |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
251 |
'USER_DETAILS_SERIALIZER': 'notes.api.serializers.auth.UserDetailsSerializer' |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
252 |
} |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
253 |
|
|
36
36210c4f019f
reorganize urls and add user management api urls
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
254 |
OLD_PASSWORD_FIELD_ENABLED = True |
| 39 | 255 |
|
|
133
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
256 |
# JWT settings |
|
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
|
257 |
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
|
258 |
'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
|
259 |
'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
|
260 |
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
|
261 |
), |
|
2a861fed6bde
Deauthenticate user if refresh was not possible (session expired or total delta reached)
ymh <ymh.work@gmail.com>
parents:
60
diff
changeset
|
262 |
'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
|
263 |
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
|
264 |
) |
|
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
|
265 |
} |
|
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
|
266 |
|
| 39 | 267 |
# CORS Headers |
268 |
CORS_ORIGIN_ALLOW_ALL = True |
|
|
97
69eaef18b01b
Improve the network saga. Try to avoid unnecessary token refresh
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
269 |
CORS_ALLOW_CREDENTIALS = True |
|
69eaef18b01b
Improve the network saga. Try to avoid unnecessary token refresh
ymh <ymh.work@gmail.com>
parents:
88
diff
changeset
|
270 |
|
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
271 |
CORS_ALLOW_HEADERS = default_headers + ( |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
272 |
'auditlog-client', |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
273 |
) |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
274 |
|
| 39 | 275 |
CORS_URLS_REGEX = r'^/api/.*$' |