From 731f3667032c7ebfed01940a840208b24c5fcf94 Mon Sep 17 00:00:00 2001 From: Fred Pauchet Date: Thu, 24 Sep 2020 21:41:52 +0200 Subject: [PATCH] Integrate django-environ, to specify environment variables. The `base_settings` file is moved to `settings.py`, to scratch default MySQL configuration. Requirements are updated to allow a seemless default installation and configuration. Should fix https://sources.grimbox.be/Sulley/khana/issues/5 --- README.md | 15 ++++ requirements/base.txt | 5 +- src/khana/base_settings.py | 132 -------------------------------- src/khana/settings.py | 153 ++++++++++++++++++++++++++++++++++--- 4 files changed, 160 insertions(+), 145 deletions(-) delete mode 100644 src/khana/base_settings.py diff --git a/README.md b/README.md index 1a6b1be..a945a2e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,21 @@ Le but de cette application est de permettre une gestion des gymnastes tout au l (plus d'information à venir) +## Installation + +```bash +pip install -r requirements/base.txt +``` + +Par défaut, Khana est configuré pour tourner dans un environnement SQLite3. Pour spécifier l'emplacement de la base de données, utilisez l'une des syntaxes ci-dessous, et spécifiez-la dans le fichier `src/khana/.env`: + +```text +# src/khana/.env + +DATABASE_URL=mysql://user:password@127.0.0.1:3306/dbname +DATABASE_URL=psql://user:un-githubbedpassword@127.0.0.1:8458/database +``` + Voici la liste des principaux modules. ## Objectifs diff --git a/requirements/base.txt b/requirements/base.txt index b5f4e7f..04dcf83 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -6,4 +6,7 @@ reportlab==3.5.34 simplejson==3.17.0 Sphinx==2.4.1 django-extensions==2.2.8 -djangorestframework==3.11.0 \ No newline at end of file +djangorestframework==3.11.0 + +django-environ==0.4.5 +pendulum==2.1.2 diff --git a/src/khana/base_settings.py b/src/khana/base_settings.py deleted file mode 100644 index 5a46a56..0000000 --- a/src/khana/base_settings.py +++ /dev/null @@ -1,132 +0,0 @@ -""" -Django settings for khana project. - -Generated by 'django-admin startproject' using Django 1.8.2. - -For more information on this file, see -https://docs.djangoproject.com/en/1.8/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.8/ref/settings/ -""" - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -import os - -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "6@9p0g-5ebcttbt$^*s4rda5!piezt6b7wj35g(+$mgz52k#d=" - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True -ALLOWED_HOSTS = ["*"] - - -# Application definition -INSTALLED_APPS = ( - "django.contrib.contenttypes", - "django.contrib.admin", - # 'django.contrib.admindocs', - "django.contrib.auth", - "django.contrib.sessions", - "django.contrib.messages", - "django.contrib.staticfiles", - "django_extensions", - "people", - "location", - "planning", - "objective", - "competition", - "profile", - "tools", - "communication", - "rest_framework", - # 'django_spaghetti', -) - -MIDDLEWARE = [ - "django.middleware.security.SecurityMiddleware", - "django.contrib.sessions.middleware.SessionMiddleware", - "django.middleware.common.CommonMiddleware", - #'django.middleware.csrf.CsrfViewMiddleware', - "django.contrib.auth.middleware.AuthenticationMiddleware", - "django.contrib.messages.middleware.MessageMiddleware", - #'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = "khana.urls" - -TEMPLATES = [ - { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [os.path.join(BASE_DIR, "templates"),], - "APP_DIRS": True, - "OPTIONS": { - "context_processors": [ - "django.template.context_processors.debug", - "django.template.context_processors.request", - "django.contrib.auth.context_processors.auth", - "django.contrib.messages.context_processors.messages", - "django.template.context_processors.media", - ], - }, - }, -] - -# WSGI_APPLICATION = 'khana.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/1.8/ref/settings/#databases - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": "khana.db", - "USER": "", - "PASSWORD": "", - "HOST": "", # Or an IP Address that your DB is hosted on - "PORT": "", - } -} - - -# Internationalization -# https://docs.djangoproject.com/en/1.8/topics/i18n/ - -# LANGUAGE_CODE = 'fr-FR' # en-US -LANGUAGE_CODE = "en-US" - -TIME_ZONE = "UTC" - -USE_I18N = True - -USE_L10N = True - -USE_TZ = False # True - -APPEND_SLASH = False # <== a mettre pour mes scripts des listes de présence ??? - -LOGIN_URL = "/login/" - -LOGOUT_URL = "/logout/" - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.8/howto/static-files/ - -STATIC_URL = "/static/" - -STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),) - -MEDIA_URL = "/media/" # https://media.khana.be - -MEDIA_ROOT = os.path.join(BASE_DIR, "media") - -DEBUG_TOOLBAR_CONFIG = { - "JQUERY_URL": STATIC_URL + "js/jquery-2.1.4.min.js", -} diff --git a/src/khana/settings.py b/src/khana/settings.py index 203266f..9b4f26a 100644 --- a/src/khana/settings.py +++ b/src/khana/settings.py @@ -1,17 +1,146 @@ -import sys -from khana.base_settings import * +""" +Django settings for khana project. + +Generated by 'django-admin startproject' using Django 1.8.2. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.8/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +import environ + + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +env = environ.Env( + DEBUG=(bool, False) +) + +environ.Env.read_env() + +DEBUG = env('DEBUG', default=True) + +SECRET_KEY = env('SECRET_KEY', default="6@9p0g-5ebcttbt$^*s4rda5!piezt6b7wj35g(+$mgz52k#d=") + +# Parse database connection url strings like psql://user:pass@127.0.0.1:8458/db +DATABASES = { + 'default': env.db('DATABASE_URL', default='sqlite:///db.sqlite3') +} + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ + + +ALLOWED_HOSTS = ["*"] + + +# Application definition +INSTALLED_APPS = ( + "django.contrib.contenttypes", + "django.contrib.admin", + # 'django.contrib.admindocs', + "django.contrib.auth", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "django_extensions", + "people", + "location", + "planning", + "objective", + "competition", + "profile", + "tools", + "communication", + "rest_framework", + # 'django_spaghetti', +) + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + #'django.middleware.csrf.CsrfViewMiddleware', + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + #'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = "khana.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [os.path.join(BASE_DIR, "templates"),], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + "django.template.context_processors.media", + ], + }, + }, +] + +# WSGI_APPLICATION = 'khana.wsgi.application' + # Database # https://docs.djangoproject.com/en/1.8/ref/settings/#databases -if not "test" in sys.argv: - DATABASES = { - "default": { - "ENGINE": "django.db.backends.mysql", - "NAME": "khana", - "USER": "root", - "PASSWORD": "PC8/aQy8+w3$", - "HOST": "localhost", # Or an IP Address that your DB is hosted on - "PORT": "3306", - } +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": "khana.db", + "USER": "", + "PASSWORD": "", + "HOST": "", # Or an IP Address that your DB is hosted on + "PORT": "", } +} + + +# Internationalization +# https://docs.djangoproject.com/en/1.8/topics/i18n/ + +# LANGUAGE_CODE = 'fr-FR' # en-US +LANGUAGE_CODE = "en-US" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_L10N = True + +USE_TZ = False # True + +APPEND_SLASH = False # <== a mettre pour mes scripts des listes de présence ??? + +LOGIN_URL = "/login/" + +LOGOUT_URL = "/logout/" + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.8/howto/static-files/ + +STATIC_URL = "/static/" + +STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),) + +MEDIA_URL = "/media/" # https://media.khana.be + +MEDIA_ROOT = os.path.join(BASE_DIR, "media") + +DEBUG_TOOLBAR_CONFIG = { + "JQUERY_URL": STATIC_URL + "js/jquery-2.1.4.min.js", +} -- 2.39.5