From e7b8591ecde30a83c15bb4697772c9c76a231fb4 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 8 Mar 2016 18:14:52 -0300 Subject: [PATCH 1/7] Integra o python-decouple --- decouple.env | 12 ++++++++++++ requirements/requirements.txt | 1 + sapl/settings.py | 26 ++++++++++++++------------ 3 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 decouple.env diff --git a/decouple.env b/decouple.env new file mode 100644 index 000000000..341c5ff99 --- /dev/null +++ b/decouple.env @@ -0,0 +1,12 @@ +SECRET_KEY=!9g1-#la+#(oft(v-y1qhy$jk-2$24pdk69#b_jfqyv!*%a_)t +DEBUG=True +NAME=sapl +USER=sapl +PASSWORD=sapl +HOST=localhost +PORT=5432 +EMAIL_USE_TLS = True +EMAIL_HOST = '' +EMAIL_HOST_USER = '' +EMAIL_HOST_PASSWORD = '' +EMAIL_PORT = 587 \ No newline at end of file diff --git a/requirements/requirements.txt b/requirements/requirements.txt index fa666f49b..432561465 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -5,6 +5,7 @@ django-bower==5.1.0 django-braces==1.8.1 django-compressor==2.0 django-crispy-forms==1.6.0 +python-decouple==3.0 django-extra-views==0.7.1 django-model-utils==2.4 django-sass-processor==0.3.4 diff --git a/sapl/settings.py b/sapl/settings.py index 996a0824f..b6b4c5a6a 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -14,16 +14,18 @@ from unipath import Path from .temp_suppress_crispy_form_warnings import \ SUPRESS_CRISPY_FORM_WARNINGS_LOGGING +from decouple import config + BASE_DIR = Path(__file__).ancestor(2) # 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 = '!9g1-#la+#(oft(v-y1qhy$jk-2$24pdk69#b_jfqyv!*%a_)t' +SECRET_KEY = config('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = config('DEBUG', default=False, cast=bool) ALLOWED_HOSTS = ['*'] @@ -107,19 +109,19 @@ WSGI_APPLICATION = 'sapl.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'sapl', - 'USER': 'sapl', - 'PASSWORD': 'sapl', - 'HOST': 'localhost', - 'PORT': '5432', + 'NAME': config('NAME'), + 'USER': config('USER'), + 'PASSWORD': config('PASSWORD'), + 'HOST': config('HOST'), + 'PORT': config('PORT'), } } -EMAIL_USE_TLS = True -EMAIL_HOST = '' -EMAIL_HOST_USER = '' -EMAIL_HOST_PASSWORD = '' -EMAIL_PORT = 587 +EMAIL_USE_TLS = config('EMAIL_USE_TLS') +EMAIL_HOST = config('EMAIL_HOST') +EMAIL_HOST_USER = config('EMAIL_HOST_USER') +EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD') +EMAIL_PORT = config('EMAIL_PORT', cast=int) MAX_DOC_UPLOAD_SIZE = 5*1024*1024 # 5MB MAX_IMAGE_UPLOAD_SIZE = 2*1024*1024 # 2MB From 1f8d10f8c2f44edaff0b04130f5e81ef1f91a798 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 8 Mar 2016 19:46:20 -0300 Subject: [PATCH 2/7] Arruma o python-decouple --- decouple.env => sapl/decouple.env | 0 sapl/settings.py | 1 + sapl/test_config.py | 5 +++++ 3 files changed, 6 insertions(+) rename decouple.env => sapl/decouple.env (100%) create mode 100644 sapl/test_config.py diff --git a/decouple.env b/sapl/decouple.env similarity index 100% rename from decouple.env rename to sapl/decouple.env diff --git a/sapl/settings.py b/sapl/settings.py index b6b4c5a6a..cbaac9a7a 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -18,6 +18,7 @@ from decouple import config BASE_DIR = Path(__file__).ancestor(2) + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ diff --git a/sapl/test_config.py b/sapl/test_config.py new file mode 100644 index 000000000..5231c76d2 --- /dev/null +++ b/sapl/test_config.py @@ -0,0 +1,5 @@ +from .settings import EMAIL_PORT + + +def test_config(): + assert EMAIL_PORT == 587 From 940cfb802a5d829d6c97331c004bd72e3585e3aa Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Thu, 10 Mar 2016 13:31:19 -0300 Subject: [PATCH 3/7] Implementa e testa o settings.py utilizando o python-decouple --- sapl/settings.py | 10 +++++----- sapl/test_config.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sapl/settings.py b/sapl/settings.py index cbaac9a7a..b7f4ee978 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -111,17 +111,17 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': config('NAME'), - 'USER': config('USER'), + 'USER': config('SET_USER'), 'PASSWORD': config('PASSWORD'), 'HOST': config('HOST'), 'PORT': config('PORT'), } } -EMAIL_USE_TLS = config('EMAIL_USE_TLS') -EMAIL_HOST = config('EMAIL_HOST') -EMAIL_HOST_USER = config('EMAIL_HOST_USER') -EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD') +EMAIL_USE_TLS = config('EMAIL_USE_TLS', cast=bool) +EMAIL_HOST = config('EMAIL_HOST', cast=str) +EMAIL_HOST_USER = config('EMAIL_HOST_USER', cast=str) +EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', cast=str) EMAIL_PORT = config('EMAIL_PORT', cast=int) MAX_DOC_UPLOAD_SIZE = 5*1024*1024 # 5MB diff --git a/sapl/test_config.py b/sapl/test_config.py index 5231c76d2..fa0f8e621 100644 --- a/sapl/test_config.py +++ b/sapl/test_config.py @@ -1,5 +1,25 @@ from .settings import EMAIL_PORT +from .settings import SECRET_KEY +from .settings import DEBUG +from .settings import DATABASES +from .settings import EMAIL_USE_TLS +from .settings import EMAIL_HOST +from .settings import EMAIL_HOST_USER +from .settings import EMAIL_HOST_PASSWORD + +data = DATABASES.get('default') def test_config(): assert EMAIL_PORT == 587 + assert SECRET_KEY == '!9g1-#la+#(oft(v-y1qhy$jk-2$24pdk69#b_jfqyv!*%a_)t' + assert DEBUG is True + assert data.get('NAME') == 'sapl' + assert data.get('USER') == 'sapl' + assert data.get('PASSWORD') == 'sapl' + assert data.get('HOST') == 'localhost' + assert data.get('PORT') == '5432' + assert EMAIL_USE_TLS is True + assert EMAIL_HOST == 'smtp.interlegis.leg.br' + assert EMAIL_HOST_USER == 'sapl-test' + assert EMAIL_HOST_PASSWORD == '2BhCwbGHcZ' From 70be77dcdc881100d3e026e02afb729e906e0427 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 11 Mar 2016 14:01:02 -0300 Subject: [PATCH 4/7] Ajusta o uso do python-decouple --- requirements/requirements.txt | 2 +- sapl/settings.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 432561465..3e2575f11 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,4 +1,4 @@ - +dj-database-url django-admin-bootstrapped==2.5.7 django-bootstrap3==7.0.0 django-bower==5.1.0 diff --git a/sapl/settings.py b/sapl/settings.py index b7f4ee978..903a7a016 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -16,6 +16,8 @@ from .temp_suppress_crispy_form_warnings import \ from decouple import config +from dj_database_url import parse as db_url + BASE_DIR = Path(__file__).ancestor(2) @@ -108,14 +110,10 @@ WSGI_APPLICATION = 'sapl.wsgi.application' # https://docs.djangoproject.com/en/1.8/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': config('NAME'), - 'USER': config('SET_USER'), - 'PASSWORD': config('PASSWORD'), - 'HOST': config('HOST'), - 'PORT': config('PORT'), - } + 'default': config( + 'DATABASE_URL', + cast=db_url, + ) } EMAIL_USE_TLS = config('EMAIL_USE_TLS', cast=bool) From 2b310d8119dddf4a0af35b51d07e8f2c3ca7ae77 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 11 Mar 2016 14:34:36 -0300 Subject: [PATCH 5/7] Coloca as instrucoes, no README, de como setar o settings.py usando o python decouple --- README.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.rst b/README.rst index dfd5a50d5..2db757c98 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,19 @@ Development Environment Installation * Either run ``./manage.py migrate`` (for an empty database) or restore a database dump. +* In sapl/sapl directory create one file called ``.env``. Write the following attribuitions +in it: + +DATABASE_URL = postgresql://USER:PASSWORD@HOST:PORT/NAME +SECRET_KEY = Generate some key and paste here. You generate it using the link below. +DEBUG = [True/False] +EMAIL_USE_TLS = [True/False] +EMAIL_PORT = [Set this parameter] +EMAIL_HOST = [Set this parameter] +EMAIL_HOST_USER = [Set this parameter] +EMAIL_HOST_PASSWORD = [Set this parameter] + +`Generate your secret key here ` Instructions for Translators ============================ From ea405ba2e084736bbdb05941c059fe1f27319731 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 11 Mar 2016 14:36:21 -0300 Subject: [PATCH 6/7] Formata a atualizacao do README --- README.rst | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index 2db757c98..637a90cd3 100644 --- a/README.rst +++ b/README.rst @@ -56,19 +56,18 @@ Development Environment Installation * Either run ``./manage.py migrate`` (for an empty database) or restore a database dump. -* In sapl/sapl directory create one file called ``.env``. Write the following attribuitions -in it: - -DATABASE_URL = postgresql://USER:PASSWORD@HOST:PORT/NAME -SECRET_KEY = Generate some key and paste here. You generate it using the link below. -DEBUG = [True/False] -EMAIL_USE_TLS = [True/False] -EMAIL_PORT = [Set this parameter] -EMAIL_HOST = [Set this parameter] -EMAIL_HOST_USER = [Set this parameter] -EMAIL_HOST_PASSWORD = [Set this parameter] - -`Generate your secret key here ` +* In ``sapl/sapl`` directory create one file called ``.env``. Write the following attributes in it: + + - DATABASE_URL = postgresql://USER:PASSWORD@HOST:PORT/NAME + - SECRET_KEY = Generate some key and paste here + - DEBUG = [True/False] + - EMAIL_USE_TLS = [True/False] + - EMAIL_PORT = [Set this parameter] + - EMAIL_HOST = [Set this parameter] + - EMAIL_HOST_USER = [Set this parameter] + - EMAIL_HOST_PASSWORD = [Set this parameter] + +`Generate your secret key here `_ Instructions for Translators ============================ From 94bd19db13fd4b360b6fcca259decbd17cc913fe Mon Sep 17 00:00:00 2001 From: eduardocalil Date: Fri, 11 Mar 2016 15:16:04 -0300 Subject: [PATCH 7/7] Delete decouple.env --- sapl/decouple.env | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 sapl/decouple.env diff --git a/sapl/decouple.env b/sapl/decouple.env deleted file mode 100644 index 341c5ff99..000000000 --- a/sapl/decouple.env +++ /dev/null @@ -1,12 +0,0 @@ -SECRET_KEY=!9g1-#la+#(oft(v-y1qhy$jk-2$24pdk69#b_jfqyv!*%a_)t -DEBUG=True -NAME=sapl -USER=sapl -PASSWORD=sapl -HOST=localhost -PORT=5432 -EMAIL_USE_TLS = True -EMAIL_HOST = '' -EMAIL_HOST_USER = '' -EMAIL_HOST_PASSWORD = '' -EMAIL_PORT = 587 \ No newline at end of file