From 820000ca8359b5a61cde7d2b3dc28dc342700410 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Tue, 22 Nov 2016 21:04:06 +0100 Subject: [PATCH] make settings, env settings, and requirements less complex --- bornhack/{settings => }/.env.dist | 1 + bornhack/{settings/base.py => settings.py} | 36 ++++++++++++++++++++ bornhack/settings/__init__.py | 0 bornhack/settings/development.py | 11 ------- bornhack/settings/production.py | 38 ---------------------- bornhack/wsgi.py | 2 +- manage.py | 2 +- requirements.txt | 14 ++++++++ requirements/base.txt | 12 ------- requirements/development.txt | 2 -- requirements/production.txt | 1 - 11 files changed, 53 insertions(+), 66 deletions(-) rename bornhack/{settings => }/.env.dist (98%) rename bornhack/{settings/base.py => settings.py} (76%) delete mode 100644 bornhack/settings/__init__.py delete mode 100644 bornhack/settings/development.py delete mode 100644 bornhack/settings/production.py create mode 100644 requirements.txt delete mode 100644 requirements/base.txt delete mode 100644 requirements/development.txt delete mode 100644 requirements/production.txt diff --git a/bornhack/settings/.env.dist b/bornhack/.env.dist similarity index 98% rename from bornhack/settings/.env.dist rename to bornhack/.env.dist index 7d025aed..4cce93ec 100644 --- a/bornhack/settings/.env.dist +++ b/bornhack/.env.dist @@ -1,6 +1,7 @@ ### set database url and allowed_hosts here DATABASE_URL=postgres://username:password@host:port/database ALLOWED_HOSTS=localhost,127.0.0.1 +DEBUG=True ### changes below here are only needed for production SECRET_KEY=somethingverysecretandunique diff --git a/bornhack/settings/base.py b/bornhack/settings.py similarity index 76% rename from bornhack/settings/base.py rename to bornhack/settings.py index 40691913..9759ce78 100644 --- a/bornhack/settings/base.py +++ b/bornhack/settings.py @@ -48,6 +48,42 @@ INSTALLED_APPS = [ 'bootstrap3', ] +DEBUG = env('DEBUG') +if DEBUG: + EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + INSTALLED_APPS += ['debug_toolbar', ] +else: + EMAIL_HOST = env('EMAIL_HOST') + EMAIL_PORT = env('EMAIL_PORT') + EMAIL_HOST_USER = env('EMAIL_HOST_USER') + EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD') + EMAIL_USE_TLS = env('EMAIL_USE_TLS') + DEFAULT_FROM_EMAIL = env('DEFAULT_FROM_EMAIL') + SERVER_EMAIL = env('DEFAULT_FROM_EMAIL') + ARCHIVE_EMAIL = env('ARCHIVE_EMAIL') + + LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'mail_admins': { + 'level': 'ERROR', + 'class': 'django.utils.log.AdminEmailHandler', + }, + 'console': { + 'level':'DEBUG', + 'class':'logging.StreamHandler', + }, + }, + 'loggers': { + 'django.request': { + 'handlers': ['mail_admins'], + 'level': 'ERROR', + 'propagate': True, + }, + } + } + STATIC_URL = '/static/' STATIC_ROOT = local_dir('static') STATICFILES_DIRS = [local_dir('static_src')] diff --git a/bornhack/settings/__init__.py b/bornhack/settings/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/bornhack/settings/development.py b/bornhack/settings/development.py deleted file mode 100644 index 90f451a0..00000000 --- a/bornhack/settings/development.py +++ /dev/null @@ -1,11 +0,0 @@ -from .base import * -import environ -env = environ.Env() -environ.Env.read_env() - -DEBUG = True - -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' - -# INSTALLED_APPS += ['debug_toolbar', ] - diff --git a/bornhack/settings/production.py b/bornhack/settings/production.py deleted file mode 100644 index 0860e467..00000000 --- a/bornhack/settings/production.py +++ /dev/null @@ -1,38 +0,0 @@ -from .base import * -import environ -env = environ.Env() -environ.Env.read_env() - -DEBUG = False - -EMAIL_HOST = env('EMAIL_HOST') -EMAIL_PORT = env('EMAIL_PORT') -EMAIL_HOST_USER = env('EMAIL_HOST_USER') -EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD') -EMAIL_USE_TLS = env('EMAIL_USE_TLS') -DEFAULT_FROM_EMAIL = env('DEFAULT_FROM_EMAIL') -SERVER_EMAIL = env('DEFAULT_FROM_EMAIL') -ARCHIVE_EMAIL = env('ARCHIVE_EMAIL') - -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'handlers': { - 'mail_admins': { - 'level': 'ERROR', - 'class': 'django.utils.log.AdminEmailHandler', - }, - 'console': { - 'level':'DEBUG', - 'class':'logging.StreamHandler', - }, - }, - 'loggers': { - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, - } -} - diff --git a/bornhack/wsgi.py b/bornhack/wsgi.py index c8449a8a..8a82caa6 100644 --- a/bornhack/wsgi.py +++ b/bornhack/wsgi.py @@ -11,6 +11,6 @@ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bornhack.settings.production") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bornhack.settings") application = get_wsgi_application() diff --git a/manage.py b/manage.py index 3fd180c5..fc2fdcda 100755 --- a/manage.py +++ b/manage.py @@ -5,7 +5,7 @@ import sys if __name__ == "__main__": os.environ.setdefault( "DJANGO_SETTINGS_MODULE", - "bornhack.settings.production" + "bornhack.settings" ) from django.core.management import execute_from_command_line diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..677e072c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,14 @@ +django>=1.10 +django-allauth>=0.29.0 +django-bootstrap3>=7.0.1 +django-environ>=0.4.1 +psycopg2>=2.6.2 +PyPDF2>=1.26 +django-wkhtmltopdf>=3.1.0 +Pillow==3.2.0 +qrcode==5.3 +CommonMark==0.7.2 +django-bleach==0.3.0 +Unidecode==0.4.19 +django-debug-toolbar>=1.6 + diff --git a/requirements/base.txt b/requirements/base.txt deleted file mode 100644 index 6efaf098..00000000 --- a/requirements/base.txt +++ /dev/null @@ -1,12 +0,0 @@ -django>=1.9 -django-allauth>=0.23.0 -django-bootstrap3>=7.0.0 -django-environ>=0.4.0 -psycopg2>=2.6.1 -PyPDF2>=1.25.1 -django-wkhtmltopdf>=3.0.0 -Pillow==3.2.0 -qrcode==5.3 -CommonMark==0.6.4 -django-bleach==0.3.0 -Unidecode==0.4.19 \ No newline at end of file diff --git a/requirements/development.txt b/requirements/development.txt deleted file mode 100644 index a4481248..00000000 --- a/requirements/development.txt +++ /dev/null @@ -1,2 +0,0 @@ --r base.txt -django-debug-toolbar==1.3.2 diff --git a/requirements/production.txt b/requirements/production.txt deleted file mode 100644 index 9c9dec9e..00000000 --- a/requirements/production.txt +++ /dev/null @@ -1 +0,0 @@ --r base.txt \ No newline at end of file