Better organization of the settings files

Fixes #8
This commit is contained in:
Martin Pépin 2017-10-13 14:17:23 +02:00
parent 19f348e5d8
commit 87eddec5ec
8 changed files with 105 additions and 60 deletions

2
.gitignore vendored
View file

@ -2,5 +2,5 @@
*.swp *.swp
media/ media/
db.sqlite3 db.sqlite3
Ernestophone/settings.py Ernestophone/settings/secret.py
__pycache__ __pycache__

View file

@ -1,41 +1,38 @@
"""
Django settings for Ernestophone project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) try:
from . import secret
except ImportError:
raise ImportError(
"The secret.py file is missing.\n"
"For a development environment, simply copy secret_example.py"
)
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
MEDIA_URL = '/media/' def import_secret(name):
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') """
Shorthand for importing a value from the secret module and raising an
informative exception if a secret is missing.
"""
try:
return getattr(secret, name)
except AttributeError:
raise RuntimeError("Secret missing: {}".format(name))
STATIC_URL = '/static/' SECRET_KEY = import_secret("SECRET_KEY")
ADMINS = import_secret("ADMINS")
SERVER_EMAIL = import_secret("SERVER_EMAIL")
# Quick-start development settings - unsuitable for production DBNAME = import_secret("DBNAME")
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ DBUSER = import_secret("DBUSER")
DBPASSWD = import_secret("DBPASSWD")
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ax0|dG^AhtYfXPXgu3*e|k3l^yKpbK;$~(_%q/5C!H9yHA(Z(2'
# SECURITY WARNING: don't run with debug turned on in production! BASE_DIR = os.path.join(
DEBUG = True os.path.dirname(__file__), "..", ".."
)
ALLOWED_HOSTS = [] INSTALLED_APPS = [
ACCOUNT_CREATION_PASS = 'dummy'
# Application definition
INSTALLED_APPS = (
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
@ -47,9 +44,9 @@ INSTALLED_APPS = (
'calendrier', 'calendrier',
'propositions', 'propositions',
'pads', 'pads',
) ]
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = [
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
@ -57,24 +54,9 @@ MIDDLEWARE_CLASSES = (
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
) ]
ROOT_URLCONF = 'Ernestophone.urls' ROOT_URLCONF = "Ernestophone.urls"
WSGI_APPLICATION = 'Ernestophone.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Templates
TEMPLATES = [{ TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
@ -95,24 +77,25 @@ TEMPLATES = [{
} }
}] }]
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": DBNAME,
"USER": DBUSER,
"PASSWORD": DBPASSWD,
"HOST": "localhost",
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
# I18n
LANGUAGE_CODE = 'fr-fr' LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'UTC' TIME_ZONE = 'UTC'
USE_I18N = True USE_I18N = True
USE_L10N = True USE_L10N = True
USE_TZ = True USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATICFILES_DIRS = ( STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'), os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, 'media/partitions'), os.path.join(BASE_DIR, 'media/partitions'),

View file

@ -0,0 +1,26 @@
import os
from .common import * # noqa
from .common import BASE_DIR, INSTALLED_APPS, MIDDLEWARE_CLASSES
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
DEBUG = True
INSTALLED_APPS += ["debug_toolbar"]
MIDDLEWARE_CLASSES = (
["debug_toolbar.middleware.DebugToolbarMiddleware"]
+ MIDDLEWARE_CLASSES
)
STATIC_URL = "/static/"
MEDIA_URL = "/media/"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}

View file

@ -0,0 +1,22 @@
import os
from .common import * # noqa
from .common import BASE_DIR
DEBUG = False
ALLOWED_HOSTS = [
"ernestophone.ens.fr",
"www.ernestophone.ens.fr",
]
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(
BASE_DIR, "..", "..", "public", "ernesto", "static"
)
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(
BASE_DIR, "..", "media"
)

View file

@ -0,0 +1,7 @@
SECRET_KEY = "vpb%-1@$ha98w5^ji#@9v2_kxj)zdk5+e!9!fqniu2$#eg+46="
ADMINS = None
SERVER_EMAIL = "ernesto@localhost"
DBNAME = "ernesto"
DBUSER = "ernesto"
DBPASSWD = "YNp2rrXowJnDAFF3"

View file

@ -3,7 +3,10 @@ import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Ernestophone.settings") os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
"Ernestophone.settings.local"
)
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line

4
requirements-devel.txt Normal file
View file

@ -0,0 +1,4 @@
-r requirements.txt
django-debug-toolbar
ipython

View file

@ -1,5 +1,5 @@
Django==1.8.* Django==1.8.*
# Pour la prod # Pour la prod
ipython psycopg2
gunicorn gunicorn