Skip to content

Commit

Permalink
Use local settings module
Browse files Browse the repository at this point in the history
  • Loading branch information
Merlin Buczek committed Jun 13, 2019
1 parent 60b4489 commit b78d90e
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 104 deletions.
34 changes: 15 additions & 19 deletions config/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
"""
Base settings for mpicms project.
"""

import environ
import os

from django.utils.translation import gettext_lazy as _


ROOT_DIR = environ.Path(__file__) - 3 # (mpicms/config/settings/base.py - 3 = mpicms/)
APPS_DIR = ROOT_DIR.path('mpicms')

env = environ.Env()

# Read .env file
environ.Env.read_env()
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # (mpicms/config/settings/base.py - 3 = mpicms/)
APPS_DIR = os.path.join(ROOT_DIR, 'mpicms')

# GENERAL
# ------------------------------------------------------------------------------
DEBUG = env.bool('DJANGO_DEBUG', False)
TIME_ZONE = 'Europe/Berlin'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
Expand All @@ -28,9 +21,12 @@
# DATABASES
# ------------------------------------------------------------------------------
DATABASES = {
'default': env.db('DATABASE_URL', default='postgres:///mpicms'),
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mpicms',
'ATOMIC_REQUESTS': True,
}
}
DATABASES['default']['ATOMIC_REQUESTS'] = True

# URLS
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -135,10 +131,10 @@

# STATIC
# ------------------------------------------------------------------------------
STATIC_ROOT = str(ROOT_DIR('staticfiles'))
STATIC_ROOT = os.path.join(ROOT_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
str(APPS_DIR.path('static')),
os.path.join(APPS_DIR, 'static'),
]
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
Expand All @@ -147,7 +143,7 @@

# MEDIA
# ------------------------------------------------------------------------------
MEDIA_ROOT = str(APPS_DIR('media'))
MEDIA_ROOT = os.path.join(APPS_DIR, 'media')
MEDIA_URL = '/media/'

# TEMPLATES
Expand All @@ -156,7 +152,7 @@
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
str(APPS_DIR.path('templates')),
os.path.join(APPS_DIR, 'templates'),
],
'OPTIONS': {
'debug': DEBUG,
Expand All @@ -181,7 +177,7 @@
# FIXTURES
# ------------------------------------------------------------------------------
FIXTURE_DIRS = (
str(APPS_DIR.path('fixtures')),
os.path.join(APPS_DIR, 'fixtures'),
)

# SECURITY
Expand All @@ -193,7 +189,7 @@

# EMAIL
# ------------------------------------------------------------------------------
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

# ADMIN
# ------------------------------------------------------------------------------
Expand All @@ -210,7 +206,7 @@
)

LOCALE_PATHS = [
ROOT_DIR.path('locale'),
os.path.join(ROOT_DIR, 'locale'),
]

WAGTAILMODELTRANSLATION_TRANSLATE_SLUGS = False
Expand Down
49 changes: 0 additions & 49 deletions config/settings/ldap.py

This file was deleted.

19 changes: 14 additions & 5 deletions config/settings/local.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from .base import * # noqa
from .base import env


# GENERAL
# ------------------------------------------------------------------------------
DEBUG = True
SECRET_KEY = env('DJANGO_SECRET_KEY', default='XBlibrFtVb24Dig6CCMAw7Kv3FpXpJYmEZMdpRlnRdTzQpNdTPZ1TtvqKiQu9caf')
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=[
SECRET_KEY = 'XBlibrFtVb24Dig6CCMAw7Kv3FpXpJYmEZMdpRlnRdTzQpNdTPZ1TtvqKiQu9caf'

ALLOWED_HOSTS = [
"localhost",
"0.0.0.0",
"127.0.0.1",
])
]

# CACHES
# ------------------------------------------------------------------------------
Expand All @@ -26,7 +27,7 @@

# EMAIL
# ------------------------------------------------------------------------------
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.console.EmailBackend')
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025

Expand All @@ -36,13 +37,16 @@
'debug_toolbar',
'wagtail.contrib.styleguide',
]

MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware'] # noqa F405

DEBUG_TOOLBAR_CONFIG = {
'DISABLE_PANELS': [
'debug_toolbar.panels.redirects.RedirectsPanel',
],
'SHOW_TEMPLATE_CONTEXT': True,
}

INTERNAL_IPS = ['127.0.0.1', '10.0.2.2']

# Logging
Expand Down Expand Up @@ -75,3 +79,8 @@
},
}
}

try:
from local_settings import * # noqa
except ImportError:
pass
81 changes: 64 additions & 17 deletions config/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
from .ldap import * # noqa
from .ldap import env
import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType

from .base import * # noqa


# GENERAL
# ------------------------------------------------------------------------------
DEBUG = False
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = env('DJANGO_SECRET_KEY')
SECRET_KEY = None
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['twiki.molgen.mpg.de'])
ALLOWED_HOSTS = ['intranet.molgen.mpg.de']

# DATABASES
# ------------------------------------------------------------------------------
DATABASES['default'] = env.db('DATABASE_URL') # noqa F405
DATABASES['default']['ATOMIC_REQUESTS'] = True # noqa F405
DATABASES['default']['CONN_MAX_AGE'] = env.int('CONN_MAX_AGE', default=60) # noqa F405
DATABASES['default']['CONN_MAX_AGE'] = 60 # noqa F405

# SECURITY
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True)
SECURE_SSL_REDIRECT = True
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure
SESSION_COOKIE_SECURE = True
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure
Expand All @@ -29,11 +31,11 @@
# TODO: set this to 60 seconds first and then to 518400 once you prove the former works
SECURE_HSTS_SECONDS = 60
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool('DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS', default=True)
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload
SECURE_HSTS_PRELOAD = env.bool('DJANGO_SECURE_HSTS_PRELOAD', default=True)
SECURE_HSTS_PRELOAD = True
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
SECURE_CONTENT_TYPE_NOSNIFF = env.bool('DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True)
SECURE_CONTENT_TYPE_NOSNIFF = True

# TEMPLATES
# ------------------------------------------------------------------------------
Expand All @@ -48,17 +50,57 @@
),
]

# AUTHENTICATION
AUTHENTICATION_BACKENDS = [
'django_auth_ldap.backend.LDAPBackend',
# 'django.contrib.auth.backends.ModelBackend',
]

AUTH_LDAP_SERVER_URI = 'ldaps://ldap.molgen.mpg.de/1'

LDAP_USER_NAMES = "dc=user,dc=apps,dc=molgen,dc=mpg,dc=DE"

AUTH_LDAP_CONNECTION_OPTIONS = {
ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER
}

AUTH_LDAP_BIND_DN = "cn=mpicms,dc=ldap,dc=apps,dc=molgen,dc=mpg,dc=DE"
AUTH_LDAP_USER_SEARCH = LDAPSearch(
LDAP_USER_NAMES,
ldap.SCOPE_SUBTREE,
"(uid=%(user)s)")


AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s," + LDAP_USER_NAMES

AUTH_LDAP_FIND_GROUP_PERMS = False
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
'ou=groups,dc=example,dc=com',
ldap.SCOPE_SUBTREE,
'(objectClass=groupOfNames)',
)
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr='cn')

AUTH_LDAP_USER_ATTR_MAP = {
'first_name': 'givenName',
'last_name': 'sn',
'email': 'mail',
}

AUTH_LDAP_USER_FLAGS_BY_GROUP = {
# 'is_staff': 'cn=staff,ou=groups,dc=example,dc=com',
# 'is_superuser': 'cn=superuser,ou=groups,dc=example,dc=com',
}

# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email
DEFAULT_FROM_EMAIL = env(
'DJANGO_DEFAULT_FROM_EMAIL',
default='MPI <info@molgen.mpg.de>'
)
DEFAULT_FROM_EMAIL = 'MPI <info@molgen.mpg.de>'

# https://docs.djangoproject.com/en/dev/ref/settings/#server-email
SERVER_EMAIL = env('DJANGO_SERVER_EMAIL', default=DEFAULT_FROM_EMAIL)
SERVER_EMAIL = DEFAULT_FROM_EMAIL
# https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
EMAIL_SUBJECT_PREFIX = env('DJANGO_EMAIL_SUBJECT_PREFIX', default='[MPI CMS]')
EMAIL_SUBJECT_PREFIX = '[MPI CMS]'

# LOGGING
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -101,3 +143,8 @@
}
}
}

try:
from local_settings import * # noqa
except ImportError:
pass
3 changes: 1 addition & 2 deletions config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
"""

from .base import * # noqa
from .base import env

# GENERAL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = False
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = env("DJANGO_SECRET_KEY", default="0QnR12nkPQODr0GtLeIaTlt3PWaxYSd6WPQl5USDULW9Q3ArzCqOJRjzsrGUpg96")
SECRET_KEY = "0QnR12nkPQODr0GtLeIaTlt3PWaxYSd6WPQl5USDULW9Q3ArzCqOJRjzsrGUpg96"
# https://docs.djangoproject.com/en/dev/ref/settings/#test-runner
TEST_RUNNER = "django.test.runner.DiscoverRunner"

Expand Down
3 changes: 1 addition & 2 deletions requirements/base.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Django
Django
django-environ

# Postgres
psycopg2
psycopg2-binary

# Wagtail
wagtail
Expand Down
5 changes: 2 additions & 3 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --upgrade requirements/base.in
# pip-compile -v --output-file base.txt base.in
#
beautifulsoup4==4.6.0 # via wagtail
certifi==2019.3.9 # via requests
chardet==3.0.4 # via requests
django-environ==0.4.5
django-modelcluster==4.4 # via wagtail
django-modeltranslation==0.13.1 # via wagtail-modeltranslation
django-taggit==0.24.0 # via wagtail
Expand All @@ -18,7 +17,7 @@ draftjs-exporter==2.1.5 # via wagtail
html5lib==1.0.1 # via wagtail
idna==2.8 # via requests
pillow==5.4.1 # via wagtail
psycopg2==2.8.2
psycopg2-binary==2.8.2
pytz==2019.1 # via django, django-modelcluster, wagtail
requests==2.21.0 # via wagtail
six==1.12.0 # via html5lib, wagtail
Expand Down
5 changes: 2 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ click==7.0 # via pip-tools
coverage==4.5.3
decorator==4.4.0 # via ipython, traitlets
django-coverage-plugin==1.6.0
django-debug-toolbar==2.0a1
django-environ==0.4.5
django-debug-toolbar==1.11
django-modelcluster==4.4
django-modeltranslation==0.13.1
django-taggit==0.24.0
Expand Down Expand Up @@ -45,7 +44,7 @@ pillow==5.4.1
pip-tools==3.6.1
pluggy==0.9.0
prompt-toolkit==2.0.9 # via ipython
psycopg2==2.8.2
psycopg2-binary==2.8.2
ptyprocess==0.6.0 # via pexpect
py==1.8.0
pycodestyle==2.5.0
Expand Down
Loading

0 comments on commit b78d90e

Please sign in to comment.