diff --git a/README.rst b/README.rst index dfd5a50d5..637a90cd3 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +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 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 ============================ diff --git a/requirements/requirements.txt b/requirements/requirements.txt index fa666f49b..3e2575f11 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,10 +1,11 @@ - +dj-database-url django-admin-bootstrapped==2.5.7 django-bootstrap3==7.0.0 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..903a7a016 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -14,16 +14,21 @@ from unipath import Path from .temp_suppress_crispy_form_warnings import \ SUPRESS_CRISPY_FORM_WARNINGS_LOGGING +from decouple import config + +from dj_database_url import parse as db_url + 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 = ['*'] @@ -105,21 +110,17 @@ WSGI_APPLICATION = 'sapl.wsgi.application' # https://docs.djangoproject.com/en/1.8/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'sapl', - 'USER': 'sapl', - 'PASSWORD': 'sapl', - 'HOST': 'localhost', - 'PORT': '5432', - } + 'default': config( + 'DATABASE_URL', + cast=db_url, + ) } -EMAIL_USE_TLS = True -EMAIL_HOST = '' -EMAIL_HOST_USER = '' -EMAIL_HOST_PASSWORD = '' -EMAIL_PORT = 587 +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 MAX_IMAGE_UPLOAD_SIZE = 2*1024*1024 # 2MB diff --git a/sapl/test_config.py b/sapl/test_config.py new file mode 100644 index 000000000..fa0f8e621 --- /dev/null +++ b/sapl/test_config.py @@ -0,0 +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'