Skip to content

Commit

Permalink
Modularize settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelmv committed Jun 28, 2017
1 parent f69b5b2 commit f128cb8
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Web application to send SMS to multiple phone numbers with Twilio.

**Twilio active account required**

You need to generate your Twilio credentials in the `settings.py` file
You need to generate your Twilio credentials in the `common.py` file
or in your `ENV_VARS`, also you need a `SECRET_KEY` for your project.

Install all the requirements with:
Expand Down
1 change: 0 additions & 1 deletion home/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.conf.urls import url
from . import views
from django.contrib.auth.decorators import login_required


urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "smsuela.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "smsuela.settings.local")
try:
from django.core.management import execute_from_command_line
except ImportError:
Expand Down
Empty file added smsuela/settings/__init__.py
Empty file.
13 changes: 7 additions & 6 deletions smsuela/settings.py → smsuela/settings/common.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os
from django.core.wsgi import get_wsgi_application
import dj_database_url
from twilio.rest import Client

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = os.environ["SECRET_KEY"]

DEBUG = True
DEBUG = False

ALLOWED_HOSTS = ['*']

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

INSTALLED_APPS = [
Expand Down Expand Up @@ -63,8 +62,6 @@
}
}

if os.environ["DEBUG"] == "False":
DATABASES['default'] = dj_database_url.config()

AUTH_PASSWORD_VALIDATORS = [
{
Expand Down Expand Up @@ -98,9 +95,13 @@
USE_TZ = True

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
os.path.join(BASE_DIR, '../static')
]

STATIC_URL = '/static/'

STATIC_ROOT = 'staticfiles'

MEDIA_ROOT = 'media'

MEDIA_URL = '/media/'
8 changes: 8 additions & 0 deletions smsuela/settings/local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
""""
Local settings
- Run in Debug mode
"""

from .common import *

DEBUG = True
9 changes: 9 additions & 0 deletions smsuela/settings/production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Production settings
- Set secret key from environment variable
"""

from .common import *
import dj_database_url

DATABASES['default'] = dj_database_url.config()
5 changes: 4 additions & 1 deletion smsuela/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
url(r'^login/$', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
url(r'^logout/$', auth_views.logout, {'next_page': '/login'}, name='logout'),
url(r'^admin/', admin.site.urls),
url(r'^', include('home.urls', namespace="home")),
]
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
6 changes: 5 additions & 1 deletion smsuela/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

from django.core.wsgi import get_wsgi_application
from dj_static import Cling
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "smsuela.settings")

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "smsuela.settings.production")

application = Cling(get_wsgi_application())
application = DjangoWhiteNoise(application)

0 comments on commit f128cb8

Please sign in to comment.