diff --git a/.gitignore b/.gitignore index 5d8adc554641cd3fe7e8a817d8c8e882817a04b2..6e5803f3362371274c9b5bae96241e8db56194cb 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,7 @@ coverage .idea # Local data -settings_local.py +secrets.py *.log # Virtualenv diff --git a/note_kfet/settings/__init__.py b/note_kfet/settings/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..28c4d5d8207d111e67d780827e2c7f214cd703c7 --- /dev/null +++ b/note_kfet/settings/__init__.py @@ -0,0 +1,11 @@ +import os + +from .base import * + +app_stage = os.environ.get('DJANGO_APP_STAGE', 'dev') +if app_stage == 'prod': + from .production import * +else: + from .development import * + +from .secrets import * diff --git a/note_kfet/settings.py b/note_kfet/settings/base.py similarity index 92% rename from note_kfet/settings.py rename to note_kfet/settings/base.py index 0abdd37dc4c676787d162369edeb289588813f2b..ba6726ad5832b7c1f4df59158273c31fe030f4a2 100644 --- a/note_kfet/settings.py +++ b/note_kfet/settings/base.py @@ -8,8 +8,8 @@ import sys from django.utils.translation import gettext_lazy as _ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -PROJECT_DIR = os.path.dirname(os.path.realpath(__file__)) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) APPS_DIR = os.path.realpath(os.path.join(BASE_DIR, "apps")) sys.path.append(APPS_DIR) @@ -91,16 +91,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'note_kfet.wsgi.application' -# Database -# https://docs.djangoproject.com/en/2.2/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators diff --git a/note_kfet/settings/development.py b/note_kfet/settings/development.py new file mode 100644 index 0000000000000000000000000000000000000000..de46e35517cca35012c99291fc63b723e2a60d60 --- /dev/null +++ b/note_kfet/settings/development.py @@ -0,0 +1,47 @@ +######################## +# Development Settings # +######################## +# For local dev on your machine: +# - Enabled by default +# - use sqlite as a db engine , Debug is True. +# - standalone mail server +# - and more ... + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases +from . import * +import os + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +# Break it, fix it! +DEBUG = True + +# Mandatory ! +ALLOWED_HOSTS = ['127.0.0.1','note.comby.xyz'] + +# Emails +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +# EMAIL_USE_SSL = False +# EMAIL_HOST = 'smtp.example.org' +# EMAIL_PORT = 25 +# EMAIL_HOST_USER = 'change_me' +# EMAIL_HOST_PASSWORD = 'change_me' + +SERVER_EMAIL = 'no-reply@example.org' + +# Security settings +SECURE_CONTENT_TYPE_NOSNIFF = False +SECURE_BROWSER_XSS_FILTER = False +SESSION_COOKIE_SECURE = False +CSRF_COOKIE_SECURE = False +CSRF_COOKIE_HTTPONLY = False +X_FRAME_OPTIONS = 'DENY' +SESSION_COOKIE_AGE = 60 * 60 * 3 diff --git a/note_kfet/settings/production.py b/note_kfet/settings/production.py new file mode 100644 index 0000000000000000000000000000000000000000..834c9633939428e2fdacc76cf317c71f9dd95b27 --- /dev/null +++ b/note_kfet/settings/production.py @@ -0,0 +1,46 @@ +######################## +# Production Settings # +######################## +# For local dev on your machine: +# - Enabled by setting env variable DJANGO_APP_STAGE = 'prod' +# - use Postgresql as db engine +# - Debug should be false. +# - should have a dedicated mail server +# - and more ... + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'mydatabase', + 'USER': 'mydatabaseuser', + 'PASSWORD': 'mypassword', + 'HOST': '127.0.0.1', + 'PORT': '5432', + } +} + +# Break it, fix it! +DEBUG = True + +# Mandatory ! +ALLOWED_HOSTS = ['127.0.0.1','note.comby.xyz'] + +# Emails +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +# EMAIL_USE_SSL = False +# EMAIL_HOST = 'smtp.example.org' +# EMAIL_PORT = 25 +# EMAIL_HOST_USER = 'change_me' +# EMAIL_HOST_PASSWORD = 'change_me' + +SERVER_EMAIL = 'no-reply@example.org' + +# Security settings +SECURE_CONTENT_TYPE_NOSNIFF = False +SECURE_BROWSER_XSS_FILTER = False +SESSION_COOKIE_SECURE = False +CSRF_COOKIE_SECURE = False +CSRF_COOKIE_HTTPONLY = False +X_FRAME_OPTIONS = 'DENY' +SESSION_COOKIE_AGE = 60 * 60 * 3 diff --git a/note_kfet/settings/secrets.py_example b/note_kfet/settings/secrets.py_example new file mode 100644 index 0000000000000000000000000000000000000000..0f1394f470430e8682781efff14d09891492162f --- /dev/null +++ b/note_kfet/settings/secrets.py_example @@ -0,0 +1,2 @@ + +SECRET_KEY = 'CHANGE_ME_IN_LOCAL_SETTINGS!' diff --git a/note_kfet/settings_local.example.py b/note_kfet/settings_local.example.py deleted file mode 100644 index b539cd1889b53ff94252ae949551571e25138d1e..0000000000000000000000000000000000000000 --- a/note_kfet/settings_local.example.py +++ /dev/null @@ -1,22 +0,0 @@ -# Obligatoire, liste des host autorisés -ALLOWED_HOSTS = ['127.0.0.1'] - -# Emails -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' -# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -# EMAIL_USE_SSL = False -# EMAIL_HOST = 'smtp.example.org' -# EMAIL_PORT = 25 -# EMAIL_HOST_USER = 'change_me' -# EMAIL_HOST_PASSWORD = 'change_me' - -SERVER_EMAIL = 'no-reply@example.org' - -# Security settings -SECURE_CONTENT_TYPE_NOSNIFF = False -SECURE_BROWSER_XSS_FILTER = False -SESSION_COOKIE_SECURE = False -CSRF_COOKIE_SECURE = False -CSRF_COOKIE_HTTPONLY = False -X_FRAME_OPTIONS = 'DENY' -SESSION_COOKIE_AGE = 60 * 60 * 3 diff --git a/uwsgi_note.ini b/uwsgi_note.ini index 465430cbd9a4692d06928abe577ac04787f6598e..83c52e5016cd091456ca2634f3f42064203d4476 100644 --- a/uwsgi_note.ini +++ b/uwsgi_note.ini @@ -23,5 +23,4 @@ chmod-socket = 664 # clear environment on exit vacuum = true #Touch reload -touch-reload = /var/www/note_kfet/note_kfet/settings.py - +touch-reload = /var/www/note_kfet/note_kfet/settings/__init__.py