diff --git a/colab/management/initconfig.py b/colab/management/initconfig.py index 64223eb..b730ced 100644 --- a/colab/management/initconfig.py +++ b/colab/management/initconfig.py @@ -32,6 +32,11 @@ ALLOWED_HOSTS = [ # SOCIAL_NETWORK_ENABLED = True ## Database settings +## +## When DEBUG is True colab will create the DB on +## the repository root. In case of production settings +## (DEBUG False) the DB settings must be set. +## # DATABASES = {{ # 'default': {{ # 'ENGINE': 'django.db.backends.sqlite3', diff --git a/colab/settings.py b/colab/settings.py index 7bc3b8b..937487e 100644 --- a/colab/settings.py +++ b/colab/settings.py @@ -9,6 +9,7 @@ https://docs.djangoproject.com/en/1.7/ref/settings/ """ BROKER_URL = 'amqp://guest:guest@localhost:5672/' + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(__file__) @@ -172,10 +173,11 @@ HAYSTACK_CONNECTIONS = { } } +DEFAULT_DATABASE = os.path.join(BASE_DIR, 'colab.sqlite3') DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'colab.sqlite3'), + 'NAME': DEFAULT_DATABASE, } } @@ -252,12 +254,12 @@ REVPROXY_ADD_REMOTE_USER = True # Tastypie settings TASTYPIE_DEFAULT_FORMATS = ['json', ] -from .utils.conf import load_colab_apps, load_py_settings +from .utils import conf SOCIAL_NETWORK_ENABLED = locals().get('SOCIAL_NETWORK_ENABLED') or False -locals().update(load_colab_apps()) -locals().update(load_py_settings()) +locals().update(conf.load_colab_apps()) +locals().update(conf.load_py_settings()) COLAB_APPS = locals().get('COLAB_APPS') or {} PROXIED_APPS = {} @@ -297,3 +299,5 @@ STATICFILES_DIRS += [ TEMPLATE_DIRS += ( os.path.join(BASE_DIR, 'templates'), ) + +conf.validate_database(DATABASES, DEFAULT_DATABASE, DEBUG) diff --git a/colab/utils/conf.py b/colab/utils/conf.py index 7f93279..5df2338 100644 --- a/colab/utils/conf.py +++ b/colab/utils/conf.py @@ -5,6 +5,7 @@ import importlib import warnings from django.core.exceptions import ImproperlyConfigured +from django.utils.translation import ugettext as _ class InaccessibleSettings(ImproperlyConfigured): @@ -13,6 +14,14 @@ class InaccessibleSettings(ImproperlyConfigured): Check if the file exists and if you have read permissions.""" +class DatabaseUndefined(ImproperlyConfigured): + """Default database is not set. + + When DEBUG is set to True a local sqlite database can be used for + developement porposes but otherwise the `default` database must + be set.""" + + def _load_py_file(py_path, path): original_path = sys.path @@ -94,3 +103,11 @@ def load_colab_apps(): COLAB_APPS[app_name][key] = value return {'COLAB_APPS': COLAB_APPS} + + +def validate_database(database_dict, default_db, debug): + db_name = database_dict.get('default', {}).get('NAME') + if not debug and db_name == default_db: + msg = _('Since DEBUG is set to False DATABASE must be set on ' + 'colab settings') + raise DatabaseUndefined(msg) -- libgit2 0.21.2