| lombardofr | 3218b2b | 2018-10-29 13:41:08 +0100 | [diff] [blame] | 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 | # |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 16 | |
| 17 | import os |
| Benjamin Diaz | c38fffb | 2019-07-24 15:57:38 -0300 | [diff] [blame] | 18 | import sys |
| 19 | |
| Benjamin Diaz | 65f0dc4 | 2019-05-24 17:54:48 -0300 | [diff] [blame] | 20 | from sqlalchemy.engine.url import make_url |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 21 | |
| 22 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
| 23 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 24 | |
| 25 | |
| 26 | # Quick-start development settings - unsuitable for production |
| 27 | # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ |
| 28 | |
| 29 | # SECURITY WARNING: keep the secret key used in production secret! |
| 30 | SECRET_KEY = 'o5+o2jv(3-dqr(&ia#-@79cgr%xi*s+6xjws^8cxp211ge#buf' |
| lombardofr | c89a4a0 | 2018-09-02 16:15:25 +0200 | [diff] [blame] | 31 | if os.getenv('DJANGO_ENV') == 'prod': |
| 32 | DEBUG = False |
| 33 | else: |
| 34 | DEBUG = True |
| lombardofr | 3fcf21a | 2019-03-11 10:26:08 +0100 | [diff] [blame] | 35 | |
| lombardofr | c89a4a0 | 2018-09-02 16:15:25 +0200 | [diff] [blame] | 36 | ALLOWED_HOSTS = ['*'] |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 37 | |
| lombardofr | 099364f | 2018-06-12 11:21:02 +0200 | [diff] [blame] | 38 | AUTH_USER_MODEL = "authosm.OsmUser" |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 39 | |
| lombardof | 3384829 | 2018-05-08 10:12:14 +0200 | [diff] [blame] | 40 | SITE_NAME = "Open Source MANO" |
| 41 | SHORT_SITE_NAME = "OSM" |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 42 | |
| 43 | LOGIN_URL = '/auth/' |
| 44 | LOGOUT_URL = '/auth/' |
| 45 | |
| 46 | VERSION = "0.0.1" |
| 47 | |
| 48 | |
| 49 | # Application definition |
| 50 | INSTALLED_APPS = [ |
| 51 | 'django.contrib.admin', |
| 52 | 'django.contrib.auth', |
| 53 | 'django.contrib.contenttypes', |
| 54 | 'django.contrib.messages', |
| 55 | 'django.contrib.staticfiles', |
| lombardofr | 0793022 | 2018-06-19 16:59:45 +0200 | [diff] [blame] | 56 | 'django.contrib.sessions', |
| lombardofr | 099364f | 2018-06-12 11:21:02 +0200 | [diff] [blame] | 57 | 'authosm', |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 58 | 'projecthandler', |
| lombardofr | e1ed7b2 | 2018-12-19 17:27:24 +0100 | [diff] [blame] | 59 | 'packagehandler', |
| lombardofr | 3218b2b | 2018-10-29 13:41:08 +0100 | [diff] [blame] | 60 | 'descriptorhandler', |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 61 | 'vimhandler', |
| lombardofr | 3fcf21a | 2019-03-11 10:26:08 +0100 | [diff] [blame] | 62 | 'wimhandler', |
| lombardof | a03da5e | 2018-06-02 18:36:44 +0200 | [diff] [blame] | 63 | 'instancehandler', |
| lombardofr | 099364f | 2018-06-12 11:21:02 +0200 | [diff] [blame] | 64 | 'sdnctrlhandler', |
| lombardofr | c3051ef | 2019-01-16 10:59:18 +0100 | [diff] [blame] | 65 | 'userhandler', |
| lombardofr | 8da2313 | 2019-06-02 17:18:48 +0200 | [diff] [blame] | 66 | 'rolehandler', |
| lombardofr | c3051ef | 2019-01-16 10:59:18 +0100 | [diff] [blame] | 67 | 'netslicehandler' |
| lombardofr | 099364f | 2018-06-12 11:21:02 +0200 | [diff] [blame] | 68 | |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 69 | ] |
| 70 | |
| 71 | MIDDLEWARE_CLASSES = [ |
| 72 | 'django.middleware.security.SecurityMiddleware', |
| 73 | 'django.contrib.sessions.middleware.SessionMiddleware', |
| lombardofr | 99f922f | 2018-07-17 17:27:36 +0200 | [diff] [blame] | 74 | 'projecthandler.middleware.OsmProjectMiddleware', |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 75 | 'django.middleware.common.CommonMiddleware', |
| 76 | 'django.middleware.csrf.CsrfViewMiddleware', |
| 77 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 78 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', |
| 79 | 'django.contrib.messages.middleware.MessageMiddleware', |
| 80 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
| 81 | |
| lombardofr | 99f922f | 2018-07-17 17:27:36 +0200 | [diff] [blame] | 82 | |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 83 | ] |
| 84 | |
| lombardofr | 0793022 | 2018-06-19 16:59:45 +0200 | [diff] [blame] | 85 | SESSION_ENGINE ='django.contrib.sessions.backends.db' |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 86 | SESSION_COOKIE_AGE = 3500 #25 min |
| 87 | SESSION_EXPIRE_AT_BROWSER_CLOSE = True |
| 88 | SESSION_SAVE_EVERY_REQUEST = True |
| 89 | |
| 90 | ROOT_URLCONF = 'sf_t3d.urls' |
| 91 | |
| 92 | TEMPLATES = [ |
| 93 | { |
| 94 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
| 95 | 'DIRS': [ |
| 96 | os.path.join(BASE_DIR, 'template'), |
| 97 | os.path.join(BASE_DIR, 'projecthandler', 'template'), |
| 98 | os.path.join(BASE_DIR, 'projecthandler', 'template', 'download'), |
| 99 | os.path.join(BASE_DIR, 'projecthandler', 'template', 'project'), |
| lombardofr | e1ed7b2 | 2018-12-19 17:27:24 +0100 | [diff] [blame] | 100 | os.path.join(BASE_DIR, 'packagehandler', 'template'), |
| lombardofr | 3218b2b | 2018-10-29 13:41:08 +0100 | [diff] [blame] | 101 | os.path.join(BASE_DIR, 'descriptorhandler', 'template'), |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 102 | os.path.join(BASE_DIR, 'vimhandler', 'template'), |
| lombardofr | 3fcf21a | 2019-03-11 10:26:08 +0100 | [diff] [blame] | 103 | os.path.join(BASE_DIR, 'wimhandler', 'template'), |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 104 | os.path.join(BASE_DIR, 'instancehandler', 'template'), |
| lombardof | a03da5e | 2018-06-02 18:36:44 +0200 | [diff] [blame] | 105 | os.path.join(BASE_DIR, 'sdnctrlhandler', 'template'), |
| lombardofr | 10b52d1 | 2018-07-17 23:42:28 +0200 | [diff] [blame] | 106 | os.path.join(BASE_DIR, 'userhandler', 'templates'), |
| lombardofr | c3051ef | 2019-01-16 10:59:18 +0100 | [diff] [blame] | 107 | os.path.join(BASE_DIR, 'netslicehandler', 'template'), |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 108 | ], |
| 109 | 'APP_DIRS': True, |
| 110 | 'OPTIONS': { |
| 111 | 'context_processors': [ |
| 112 | 'django.template.context_processors.debug', |
| 113 | 'django.template.context_processors.request', |
| 114 | 'django.contrib.auth.context_processors.auth', |
| 115 | 'django.contrib.messages.context_processors.messages', |
| 116 | 'sf_t3d.context_processor.conf_constants', |
| 117 | ], |
| 118 | 'libraries':{ |
| 119 | 'get': 'sf_t3d.templatetags.get', |
| lombardof | 74ed51a | 2018-05-11 01:07:01 +0200 | [diff] [blame] | 120 | 'date_tag': 'sf_t3d.templatetags.datetag', |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 121 | } |
| 122 | }, |
| 123 | }, |
| 124 | ] |
| 125 | |
| 126 | WSGI_APPLICATION = 'sf_t3d.wsgi.application' |
| 127 | |
| 128 | |
| 129 | # Database |
| 130 | # https://docs.djangoproject.com/en/1.9/ref/settings/#databases |
| 131 | |
| Benjamin Diaz | 65f0dc4 | 2019-05-24 17:54:48 -0300 | [diff] [blame] | 132 | sql_uri = make_url(os.getenv('OSMUI_SQL_DATABASE_URI', 'sqlite:///db.sqlite3')) |
| 133 | if 'sqlite' in sql_uri.drivername: |
| 134 | DATABASES = { |
| 135 | 'default': { |
| 136 | 'ENGINE': 'django.db.backends.sqlite3', |
| 137 | 'NAME': os.path.join(BASE_DIR, sql_uri.database if sql_uri.database else 'db.sqlite3'), |
| 138 | } |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 139 | } |
| Benjamin Diaz | 65f0dc4 | 2019-05-24 17:54:48 -0300 | [diff] [blame] | 140 | else: |
| 141 | DATABASES = { |
| 142 | 'default': { |
| 143 | 'ENGINE': 'django.db.backends.mysql', |
| 144 | 'NAME': sql_uri.database if sql_uri.database else 'lwui', |
| 145 | 'USER': sql_uri.username, |
| 146 | 'PASSWORD': sql_uri.password, |
| 147 | 'HOST': sql_uri.host, |
| 148 | 'PORT': sql_uri.port, |
| 149 | } |
| 150 | } |
| 151 | |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 152 | |
| lombardofr | 099364f | 2018-06-12 11:21:02 +0200 | [diff] [blame] | 153 | AUTHENTICATION_BACKENDS = ['authosm.backend.OsmBackend'] |
| 154 | |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 155 | |
| 156 | # Password validation |
| 157 | # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators |
| 158 | |
| 159 | AUTH_PASSWORD_VALIDATORS = [ |
| 160 | { |
| 161 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
| 162 | }, |
| 163 | { |
| 164 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', |
| 165 | }, |
| 166 | { |
| 167 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', |
| 168 | }, |
| 169 | { |
| 170 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
| 171 | }, |
| 172 | ] |
| 173 | |
| 174 | |
| 175 | # Internationalization |
| 176 | # https://docs.djangoproject.com/en/1.9/topics/i18n/ |
| 177 | |
| 178 | LANGUAGE_CODE = 'en-us' |
| 179 | |
| 180 | TIME_ZONE = 'UTC' |
| 181 | |
| 182 | USE_I18N = True |
| 183 | |
| 184 | USE_L10N = True |
| 185 | |
| 186 | USE_TZ = True |
| 187 | |
| 188 | |
| 189 | # Static files (CSS, JavaScript, Images) |
| 190 | # https://docs.djangoproject.com/en/1.9/howto/static-files/ |
| 191 | |
| 192 | STATIC_URL = '/static/' |
| lombardofr | c89a4a0 | 2018-09-02 16:15:25 +0200 | [diff] [blame] | 193 | if DEBUG: |
| 194 | STATICFILES_FINDERS = ( |
| 195 | 'django.contrib.staticfiles.finders.FileSystemFinder', |
| 196 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', |
| 197 | 'django.contrib.staticfiles.finders.DefaultStorageFinder' |
| 198 | ) |
| 199 | STATICFILES_DIRS = ( |
| 200 | # Put strings here, like "/home/html/static" or "C:/www/django/static". |
| 201 | # Always use forward slashes, even on Windows. |
| 202 | # Don't forget to use absolute paths, not relative paths. |
| 203 | os.path.join(BASE_DIR, "static"), |
| 204 | ) |
| 205 | else: |
| 206 | STATIC_ROOT = os.path.join(BASE_DIR, "static/") |
| lombardof | fb37bca | 2018-05-03 16:20:04 +0200 | [diff] [blame] | 207 | |
| 208 | LOCALE_PATHS = ( |
| 209 | os.path.join(BASE_DIR, 'locale'), |
| lombardofr | c89a4a0 | 2018-09-02 16:15:25 +0200 | [diff] [blame] | 210 | ) |
| Benjamin Diaz | c38fffb | 2019-07-24 15:57:38 -0300 | [diff] [blame] | 211 | |
| 212 | LOGGING = { |
| 213 | 'version': 1, |
| 214 | 'disable_existing_loggers': False, |
| 215 | 'formatters': { |
| 216 | 'verbose': { |
| 217 | 'format': '[django] %(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' |
| 218 | } |
| 219 | }, |
| 220 | 'handlers': { |
| 221 | 'console': { |
| 222 | 'level': 'DEBUG', |
| 223 | 'class': 'logging.StreamHandler', |
| 224 | 'stream': sys.stdout, |
| 225 | 'formatter': 'verbose' |
| 226 | }, |
| 227 | }, |
| 228 | 'loggers': { |
| 229 | 'django': { |
| 230 | 'handlers': ['console'], |
| 231 | 'level': 'DEBUG', |
| 232 | 'propagate': True, |
| 233 | }, |
| 234 | }, |
| 235 | } |