From aac67d043ef2fe886961fffb6ae016d942c5d6a1 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 16 Sep 2014 10:59:15 -0300 Subject: [PATCH] Settings quebrado em multiplos arquivos --- .gitignore | 2 +- sigi/settings/__init__.py | 7 +++++ sigi/{settings.py => settings/base.py} | 41 ++++---------------------- sigi/settings/dev.py | 26 ++++++++++++++++ 4 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 sigi/settings/__init__.py rename sigi/{settings.py => settings/base.py} (75%) create mode 100644 sigi/settings/dev.py diff --git a/.gitignore b/.gitignore index 3a4994c..b65afa7 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,4 @@ static .pydevproject .vagrant -sigi/local_settings.py +sigi/settings/prod.py diff --git a/sigi/settings/__init__.py b/sigi/settings/__init__.py new file mode 100644 index 0000000..aa5057f --- /dev/null +++ b/sigi/settings/__init__.py @@ -0,0 +1,7 @@ +try: + from prod import * +except ImportError: + from warnings import warn + msg = "You don't have a production settings file, using development settings." + warn(msg, category=ImportWarning) + from dev import * diff --git a/sigi/settings.py b/sigi/settings/base.py similarity index 75% rename from sigi/settings.py rename to sigi/settings/base.py index 748a6a0..4c85c9f 100644 --- a/sigi/settings.py +++ b/sigi/settings/base.py @@ -10,19 +10,16 @@ https://docs.djangoproject.com/en/dev/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +from os.path import dirname + import django.conf.global_settings as DEFAULT_SETTINGS -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + +BASE_DIR = dirname(dirname(dirname(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/ -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '0$ip1fb5xtq%a=)-k_4r^(#jn0t^@+*^kihkxkozg-mip7+w3+' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True -TEMPLATE_DEBUG = DEBUG ALLOWED_HOSTS = [] ADMINS = ( @@ -39,8 +36,7 @@ TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + ( # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', - ) - + ) # Application definition INSTALLED_APPS = ( @@ -85,16 +81,6 @@ MIDDLEWARE_CLASSES = ( ROOT_URLCONF = 'sigi.urls' WSGI_APPLICATION = 'sigi.wsgi.application' -# Database -# https://docs.djangoproject.com/en/dev/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'sigi.db'), - } -} - # Internationalization # https://docs.djangoproject.com/en/dev/topics/i18n/ LANGUAGE_CODE = 'pt-br' @@ -121,20 +107,3 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' SESSION_EXPIRE_AT_BROWSER_CLOSE = True - -CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', - } -} - -try: - from local_settings import * -except ImportError: - from warnings import warn - msg = "You don't have local_settings.py file, using defaults settings." - try: - # don't work in Python 2.4 or before - warn(msg, category=ImportWarning) - except NameError: - warn(msg) diff --git a/sigi/settings/dev.py b/sigi/settings/dev.py new file mode 100644 index 0000000..c9152e3 --- /dev/null +++ b/sigi/settings/dev.py @@ -0,0 +1,26 @@ +from base import * + + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '0$ip1fb5xtq%a=)-k_4r^(#jn0t^@+*^kihkxkozg-mip7+w3+' + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'sigi.db'), + } +} + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +INSTALLED_APPS += ( + 'debug_toolbar', +) + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', + } +}