Enables use of mysql database as backend for session storage 48/7548/1
authorBenjamin Diaz <bdiaz@whitestack.com>
Fri, 24 May 2019 20:54:48 +0000 (17:54 -0300)
committerBenjamin Diaz <bdiaz@whitestack.com>
Fri, 24 May 2019 20:54:50 +0000 (17:54 -0300)
Depends-On: I52d1ef046d2c3804f305c57f8d35889dd1f038f7
Change-Id: Idc2b43f09cc749c2ef160bc4440e9a6dbddc5167
Signed-off-by: Benjamin Diaz <bdiaz@whitestack.com>
sf_t3d/settings.py

index d000e65..768152a 100644 (file)
@@ -15,6 +15,7 @@
 #
 
 import os
 #
 
 import os
+from sqlalchemy.engine.url import make_url
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -125,12 +126,26 @@ WSGI_APPLICATION = 'sf_t3d.wsgi.application'
 # Database
 # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
 
 # Database
 # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
 
-DATABASES = {
-    'default': {
-        'ENGINE': 'django.db.backends.sqlite3',
-        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+sql_uri = make_url(os.getenv('OSMUI_SQL_DATABASE_URI', 'sqlite:///db.sqlite3'))
+if 'sqlite' in sql_uri.drivername:
+    DATABASES = {
+        'default': {
+            'ENGINE': 'django.db.backends.sqlite3',
+            'NAME': os.path.join(BASE_DIR, sql_uri.database if sql_uri.database else 'db.sqlite3'),
+        }
     }
     }
-}
+else:
+    DATABASES = {
+        'default': {
+            'ENGINE': 'django.db.backends.mysql',
+            'NAME': sql_uri.database if sql_uri.database else 'lwui',
+            'USER': sql_uri.username,
+            'PASSWORD': sql_uri.password,
+            'HOST': sql_uri.host,
+            'PORT': sql_uri.port,
+        }
+    }
+
 
 AUTHENTICATION_BACKENDS = ['authosm.backend.OsmBackend']
 
 
 AUTHENTICATION_BACKENDS = ['authosm.backend.OsmBackend']