Commit b71fe7377ea7a34c0995c8b0f499f783428cb9a9

Authored by Sergio Oliveira
1 parent 47ca4d8d

Don't allow auto db conf if debug is False

colab/management/initconfig.py
... ... @@ -32,6 +32,11 @@ ALLOWED_HOSTS = [
32 32 # SOCIAL_NETWORK_ENABLED = True
33 33  
34 34 ## Database settings
  35 +##
  36 +## When DEBUG is True colab will create the DB on
  37 +## the repository root. In case of production settings
  38 +## (DEBUG False) the DB settings must be set.
  39 +##
35 40 # DATABASES = {{
36 41 # 'default': {{
37 42 # 'ENGINE': 'django.db.backends.sqlite3',
... ...
colab/settings.py
... ... @@ -9,6 +9,7 @@ https://docs.djangoproject.com/en/1.7/ref/settings/
9 9 """
10 10  
11 11 BROKER_URL = 'amqp://guest:guest@localhost:5672/'
  12 +
12 13 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
13 14 import os
14 15 BASE_DIR = os.path.dirname(__file__)
... ... @@ -172,10 +173,11 @@ HAYSTACK_CONNECTIONS = {
172 173 }
173 174 }
174 175  
  176 +DEFAULT_DATABASE = os.path.join(BASE_DIR, 'colab.sqlite3')
175 177 DATABASES = {
176 178 'default': {
177 179 'ENGINE': 'django.db.backends.sqlite3',
178   - 'NAME': os.path.join(BASE_DIR, 'colab.sqlite3'),
  180 + 'NAME': DEFAULT_DATABASE,
179 181 }
180 182 }
181 183  
... ... @@ -252,12 +254,12 @@ REVPROXY_ADD_REMOTE_USER = True
252 254 # Tastypie settings
253 255 TASTYPIE_DEFAULT_FORMATS = ['json', ]
254 256  
255   -from .utils.conf import load_colab_apps, load_py_settings
  257 +from .utils import conf
256 258  
257 259 SOCIAL_NETWORK_ENABLED = locals().get('SOCIAL_NETWORK_ENABLED') or False
258 260  
259   -locals().update(load_colab_apps())
260   -locals().update(load_py_settings())
  261 +locals().update(conf.load_colab_apps())
  262 +locals().update(conf.load_py_settings())
261 263  
262 264 COLAB_APPS = locals().get('COLAB_APPS') or {}
263 265 PROXIED_APPS = {}
... ... @@ -297,3 +299,5 @@ STATICFILES_DIRS += [
297 299 TEMPLATE_DIRS += (
298 300 os.path.join(BASE_DIR, 'templates'),
299 301 )
  302 +
  303 +conf.validate_database(DATABASES, DEFAULT_DATABASE, DEBUG)
... ...
colab/utils/conf.py
... ... @@ -5,6 +5,7 @@ import importlib
5 5 import warnings
6 6  
7 7 from django.core.exceptions import ImproperlyConfigured
  8 +from django.utils.translation import ugettext as _
8 9  
9 10  
10 11 class InaccessibleSettings(ImproperlyConfigured):
... ... @@ -13,6 +14,14 @@ class InaccessibleSettings(ImproperlyConfigured):
13 14 Check if the file exists and if you have read permissions."""
14 15  
15 16  
  17 +class DatabaseUndefined(ImproperlyConfigured):
  18 + """Default database is not set.
  19 +
  20 + When DEBUG is set to True a local sqlite database can be used for
  21 + developement porposes but otherwise the `default` database must
  22 + be set."""
  23 +
  24 +
16 25 def _load_py_file(py_path, path):
17 26 original_path = sys.path
18 27  
... ... @@ -94,3 +103,11 @@ def load_colab_apps():
94 103 COLAB_APPS[app_name][key] = value
95 104  
96 105 return {'COLAB_APPS': COLAB_APPS}
  106 +
  107 +
  108 +def validate_database(database_dict, default_db, debug):
  109 + db_name = database_dict.get('default', {}).get('NAME')
  110 + if not debug and db_name == default_db:
  111 + msg = _('Since DEBUG is set to False DATABASE must be set on '
  112 + 'colab settings')
  113 + raise DatabaseUndefined(msg)
... ...