· 5 years ago · Jan 11, 2020, 11:58 AM
1import environ
2from datetime import timedelta
3
4ROOT_DIR = environ.Path(__file__) - 2
5
6# Load operating system environment variables and then prepare to use them
7env = environ.Env()
8
9# APP CONFIGURATION
10# ------------------------------------------------------------------------------
11DJANGO_APPS = [
12 'django.contrib.auth',
13 'django.contrib.contenttypes',
14 'django.contrib.sessions',
15 'django.contrib.messages',
16 'django.contrib.staticfiles',
17 'django.contrib.admin',
18]
19
20THIRD_PARTY_APPS = [
21 'rest_framework',
22 'django_extensions',
23 'djmoney',
24 'organizations',
25 'org_permissions'
26]
27
28LOCAL_APPS = [
29 'apps.users',
30 'apps.ranges',
31]
32
33# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
34INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
35
36# MIDDLEWARE CONFIGURATION
37# ------------------------------------------------------------------------------
38MIDDLEWARE = [
39 'django.middleware.security.SecurityMiddleware',
40 'django.contrib.sessions.middleware.SessionMiddleware',
41 'django.middleware.common.CommonMiddleware',
42 'django.middleware.csrf.CsrfViewMiddleware',
43 'django.contrib.auth.middleware.AuthenticationMiddleware',
44 'django.contrib.messages.middleware.MessageMiddleware',
45 'django.middleware.clickjacking.XFrameOptionsMiddleware',
46]
47
48# DEBUG
49# ------------------------------------------------------------------------------
50# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
51DEBUG = env.bool('DEBUG')
52SECRET_KEY = env.str('SECRET_KEY')
53
54# DOMAINS
55ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=['*'])
56DOMAIN = env.str('DOMAIN')
57
58# EMAIL CONFIGURATION
59# ------------------------------------------------------------------------------
60EMAIL_PORT = env.int('EMAIL_PORT', default='1025')
61EMAIL_HOST = env.str('EMAIL_HOST', default='mailhog')
62
63# MANAGER CONFIGURATION
64# ------------------------------------------------------------------------------
65# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
66ADMINS = [
67 ('io', 'admin@comp.com'),
68]
69
70# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
71MANAGERS = ADMINS
72
73# DATABASE CONFIGURATION
74# ------------------------------------------------------------------------------
75# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
76DATABASES = {
77 'default': {
78 'ENGINE': 'django.db.backends.postgresql_psycopg2',
79 'NAME': env.str('POSTGRES_DB'),
80 'USER': env.str('POSTGRES_USER'),
81 'PASSWORD': env.str('POSTGRES_PASSWORD'),
82 'HOST': 'postgres',
83 'PORT': 5432,
84 },
85}
86
87# GENERAL CONFIGURATION
88# ------------------------------------------------------------------------------
89# Local time zone for this installation. Choices can be found here:
90# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
91# although not all choices may be available on all operating systems.
92# In a Windows environment this must be set to your system time zone.
93TIME_ZONE = 'UTC'
94
95# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
96LANGUAGE_CODE = 'en-us'
97
98# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
99USE_I18N = True
100
101# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
102USE_L10N = True
103
104# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
105USE_TZ = True
106
107# STATIC FILE CONFIGURATION
108# ------------------------------------------------------------------------------
109# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
110STATIC_ROOT = str(ROOT_DIR('staticfiles'))
111
112# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
113STATIC_URL = '/staticfiles/'
114
115# See:
116# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
117STATICFILES_DIRS = [
118 str(ROOT_DIR('static')),
119]
120
121# See:
122# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
123STATICFILES_FINDERS = [
124 'django.contrib.staticfiles.finders.FileSystemFinder',
125 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
126]
127
128# MEDIA CONFIGURATION
129# ------------------------------------------------------------------------------
130# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
131MEDIA_ROOT = str(ROOT_DIR('media'))
132
133# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
134MEDIA_URL = '/media/'
135
136# URL Configuration
137# ------------------------------------------------------------------------------
138ROOT_URLCONF = 'config.urls'
139
140# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
141WSGI_APPLICATION = 'config.wsgi.application'
142
143# TEMPLATE CONFIGURATION
144# ------------------------------------------------------------------------------
145# See: https://docs.djangoproject.com/en/dev/ref/settings/#templates
146TEMPLATES = [
147 {
148 'BACKEND': 'django.template.backends.django.DjangoTemplates',
149 'DIRS': STATICFILES_DIRS,
150 'OPTIONS': {
151 'debug': DEBUG,
152 'loaders': [
153 'django.template.loaders.filesystem.Loader',
154 'django.template.loaders.app_directories.Loader',
155 ],
156 'context_processors': [
157 'django.template.context_processors.debug',
158 'django.template.context_processors.request',
159 'django.contrib.auth.context_processors.auth',
160 'django.template.context_processors.i18n',
161 'django.template.context_processors.media',
162 'django.template.context_processors.static',
163 'django.template.context_processors.tz',
164 'django.contrib.messages.context_processors.messages',
165 ],
166 },
167 },
168]
169
170
171# PASSWORD STORAGE SETTINGS
172# ------------------------------------------------------------------------------
173# See https://docs.djangoproject.com/en/dev/ref/settings/#password-hashers
174PASSWORD_HASHERS = [
175 'django.contrib.auth.hashers.PBKDF2PasswordHasher',
176 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
177 'django.contrib.auth.hashers.Argon2PasswordHasher',
178 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
179 'django.contrib.auth.hashers.BCryptPasswordHasher',
180]
181
182# PASSWORD VALIDATION
183# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
184# ------------------------------------------------------------------------------
185AUTH_PASSWORD_VALIDATORS = [
186 {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
187 {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
188 {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
189 {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
190]
191
192# AUTHENTICATION CONFIGURATION
193# ------------------------------------------------------------------------------
194AUTHENTICATION_BACKENDS = [
195
196 'django.contrib.auth.backends.ModelBackend',
197 'org_permissions.auth_backends.OrganizationModelBackend',
198]
199
200# Custom user app defaults
201# Select the correct user model
202AUTH_USER_MODEL = 'users.User'
203
204
205# DJANGO REST FRAMEWORK
206# ------------------------------------------------------------------------------
207REST_FRAMEWORK = {
208 'UPLOADED_FILES_USE_URL': False,
209 'DEFAULT_AUTHENTICATION_CLASSES': [
210 'rest_framework.authentication.SessionAuthentication',
211 'rest_framework.authentication.BasicAuthentication'
212 ],
213 'DEFAULT_PERMISSION_CLASSES': ['org_permissions.permissions.ModelPermissions'],
214 'DEFAULT_PARSER_CLASSES': [
215 'rest_framework.parsers.JSONParser',
216 'rest_framework.parsers.FormParser',
217 'rest_framework.parsers.MultiPartParser',
218 'rest_framework.parsers.FileUploadParser'
219 ]
220}