Enables use of mysql database as backend for session storage
[osm/LW-UI.git] / sf_t3d / settings.py
1 #
2 # Copyright 2018 EveryUP Srl
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 import os
18 from sqlalchemy.engine.url import make_url
19
20 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
21 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
22
23
24 # Quick-start development settings - unsuitable for production
25 # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
26
27 # SECURITY WARNING: keep the secret key used in production secret!
28 SECRET_KEY = 'o5+o2jv(3-dqr(&ia#-@79cgr%xi*s+6xjws^8cxp211ge#buf'
29 if os.getenv('DJANGO_ENV') == 'prod':
30 DEBUG = False
31 else:
32 DEBUG = True
33
34 ALLOWED_HOSTS = ['*']
35
36 AUTH_USER_MODEL = "authosm.OsmUser"
37
38 SITE_NAME = "Open Source MANO"
39 SHORT_SITE_NAME = "OSM"
40
41 LOGIN_URL = '/auth/'
42 LOGOUT_URL = '/auth/'
43
44 VERSION = "0.0.1"
45
46
47 # Application definition
48 INSTALLED_APPS = [
49 'django.contrib.admin',
50 'django.contrib.auth',
51 'django.contrib.contenttypes',
52 'django.contrib.messages',
53 'django.contrib.staticfiles',
54 'django.contrib.sessions',
55 'authosm',
56 'projecthandler',
57 'packagehandler',
58 'descriptorhandler',
59 'vimhandler',
60 'wimhandler',
61 'instancehandler',
62 'sdnctrlhandler',
63 'userhandler',
64 'netslicehandler'
65
66 ]
67
68 MIDDLEWARE_CLASSES = [
69 'django.middleware.security.SecurityMiddleware',
70 'django.contrib.sessions.middleware.SessionMiddleware',
71 'projecthandler.middleware.OsmProjectMiddleware',
72 'django.middleware.common.CommonMiddleware',
73 'django.middleware.csrf.CsrfViewMiddleware',
74 'django.contrib.auth.middleware.AuthenticationMiddleware',
75 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
76 'django.contrib.messages.middleware.MessageMiddleware',
77 'django.middleware.clickjacking.XFrameOptionsMiddleware',
78
79
80 ]
81
82 SESSION_ENGINE ='django.contrib.sessions.backends.db'
83 SESSION_COOKIE_AGE = 3500 #25 min
84 SESSION_EXPIRE_AT_BROWSER_CLOSE = True
85 SESSION_SAVE_EVERY_REQUEST = True
86
87 ROOT_URLCONF = 'sf_t3d.urls'
88
89 TEMPLATES = [
90 {
91 'BACKEND': 'django.template.backends.django.DjangoTemplates',
92 'DIRS': [
93 os.path.join(BASE_DIR, 'template'),
94 os.path.join(BASE_DIR, 'projecthandler', 'template'),
95 os.path.join(BASE_DIR, 'projecthandler', 'template', 'download'),
96 os.path.join(BASE_DIR, 'projecthandler', 'template', 'project'),
97 os.path.join(BASE_DIR, 'packagehandler', 'template'),
98 os.path.join(BASE_DIR, 'descriptorhandler', 'template'),
99 os.path.join(BASE_DIR, 'vimhandler', 'template'),
100 os.path.join(BASE_DIR, 'wimhandler', 'template'),
101 os.path.join(BASE_DIR, 'instancehandler', 'template'),
102 os.path.join(BASE_DIR, 'sdnctrlhandler', 'template'),
103 os.path.join(BASE_DIR, 'userhandler', 'templates'),
104 os.path.join(BASE_DIR, 'netslicehandler', 'template'),
105 ],
106 'APP_DIRS': True,
107 'OPTIONS': {
108 'context_processors': [
109 'django.template.context_processors.debug',
110 'django.template.context_processors.request',
111 'django.contrib.auth.context_processors.auth',
112 'django.contrib.messages.context_processors.messages',
113 'sf_t3d.context_processor.conf_constants',
114 ],
115 'libraries':{
116 'get': 'sf_t3d.templatetags.get',
117 'date_tag': 'sf_t3d.templatetags.datetag',
118 }
119 },
120 },
121 ]
122
123 WSGI_APPLICATION = 'sf_t3d.wsgi.application'
124
125
126 # Database
127 # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
128
129 sql_uri = make_url(os.getenv('OSMUI_SQL_DATABASE_URI', 'sqlite:///db.sqlite3'))
130 if 'sqlite' in sql_uri.drivername:
131 DATABASES = {
132 'default': {
133 'ENGINE': 'django.db.backends.sqlite3',
134 'NAME': os.path.join(BASE_DIR, sql_uri.database if sql_uri.database else 'db.sqlite3'),
135 }
136 }
137 else:
138 DATABASES = {
139 'default': {
140 'ENGINE': 'django.db.backends.mysql',
141 'NAME': sql_uri.database if sql_uri.database else 'lwui',
142 'USER': sql_uri.username,
143 'PASSWORD': sql_uri.password,
144 'HOST': sql_uri.host,
145 'PORT': sql_uri.port,
146 }
147 }
148
149
150 AUTHENTICATION_BACKENDS = ['authosm.backend.OsmBackend']
151
152
153 # Password validation
154 # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
155
156 AUTH_PASSWORD_VALIDATORS = [
157 {
158 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
159 },
160 {
161 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
162 },
163 {
164 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
165 },
166 {
167 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
168 },
169 ]
170
171
172 # Internationalization
173 # https://docs.djangoproject.com/en/1.9/topics/i18n/
174
175 LANGUAGE_CODE = 'en-us'
176
177 TIME_ZONE = 'UTC'
178
179 USE_I18N = True
180
181 USE_L10N = True
182
183 USE_TZ = True
184
185
186 # Static files (CSS, JavaScript, Images)
187 # https://docs.djangoproject.com/en/1.9/howto/static-files/
188
189 STATIC_URL = '/static/'
190 if DEBUG:
191 STATICFILES_FINDERS = (
192 'django.contrib.staticfiles.finders.FileSystemFinder',
193 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
194 'django.contrib.staticfiles.finders.DefaultStorageFinder'
195 )
196 STATICFILES_DIRS = (
197 # Put strings here, like "/home/html/static" or "C:/www/django/static".
198 # Always use forward slashes, even on Windows.
199 # Don't forget to use absolute paths, not relative paths.
200 os.path.join(BASE_DIR, "static"),
201 )
202 else:
203 STATIC_ROOT = os.path.join(BASE_DIR, "static/")
204
205 LOCALE_PATHS = (
206 os.path.join(BASE_DIR, 'locale'),
207 )