__init__.py 4.44 KB
Newer Older
Chris Lamb's avatar
Chris Lamb committed
1 2 3 4 5 6 7 8 9 10
import os
import copy
import email
import djcelery

from os.path import dirname, abspath
from celery.schedules import crontab

from django.utils.log import DEFAULT_LOGGING

11 12
from .apps import *
from .setup_warnings import *
Chris Lamb's avatar
Chris Lamb committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

djcelery.setup_loader()

BASE_DIR = '/usr/share/python/bidb'

# Fallback to relative location
if not __file__.startswith(BASE_DIR):
    BASE_DIR = dirname(dirname(dirname(dirname(abspath(__file__)))))

DEBUG = False
ALLOWED_HOSTS = ('*',)

SECRET_KEY = 'overriden-in-production'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'bidb',
        'USER': 'bidb',
        'PASSWORD': 'bidb',
        'HOST': '127.0.0.1',
        'PORT': '5432',
        'ATOMIC_REQUESTS': True,
36
    }
Chris Lamb's avatar
Chris Lamb committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
}

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'bidb.urls'
WSGI_APPLICATION = 'bidb.wsgi.application'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
56
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
Chris Lamb's avatar
Chris Lamb committed
57 58 59 60 61 62 63 64 65 66
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'bidb.utils.context_processors.settings_context',
            ],
            'builtins': [
Chris Lamb's avatar
Chris Lamb committed
67
                'django.contrib.humanize.templatetags.humanize',
Chris Lamb's avatar
Chris Lamb committed
68
                'django.contrib.staticfiles.templatetags.staticfiles',
Chris Lamb's avatar
Chris Lamb committed
69
                'bidb.utils.templatetags.pagination',
70
                'bidb.utils.templatetags.python',
Chris Lamb's avatar
Chris Lamb committed
71 72
            ],
        },
73
    }
Chris Lamb's avatar
Chris Lamb committed
74 75
]

76 77
LOGIN_URL = '/login'  # 'account:login'
LOGIN_REDIRECT_URL = '/'  # 'static:landing'
Chris Lamb's avatar
Chris Lamb committed
78 79 80 81 82 83

USE_TZ = False
TIME_ZONE = 'UTC'
USE_I18N = False
USE_L10N = False
LANGUAGE_CODE = 'en-gb'
84
DATETIME_FORMAT = 'r'  # RFC 2822
Chris Lamb's avatar
Chris Lamb committed
85 86 87 88

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'media'),)
89 90 91
STATICFILES_STORAGE = (
    'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
)
Chris Lamb's avatar
Chris Lamb committed
92 93 94

MEDIA_URL = '/storage/'
MEDIA_ROOT = 'overriden-in-production'
Chris Lamb's avatar
Chris Lamb committed
95 96 97 98 99 100 101 102 103

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

AWS_DEFAULT_ACL = 'public-read'
AWS_ACCESS_KEY_ID = 'overriden-in-production'
AWS_QUERYSTRING_AUTH = False
AWS_SECRET_ACCESS_KEY = 'overriden-in-production'
AWS_QUERYSTRING_EXPIRE = 86400 * 7 * 12
AWS_STORAGE_BUCKET_NAME = 'overriden-in-production'
Chris Lamb's avatar
Chris Lamb committed
104 105 106 107

BROKER_URL = 'redis://localhost:6379/0'

CELERYBEAT_SCHEDULE = {
108 109 110
    'keys_refresh_all': {
        'task': 'bidb.keys.tasks.refresh_all',
        'schedule': crontab(hour=0, minute=0),
111
    }
Chris Lamb's avatar
Chris Lamb committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
}

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

SITE_URL = 'overriden-in-production'
DEFAULT_FROM_EMAIL = 'overriden-in-production'

CSRF_COOKIE_SECURE = True
SESSION_COOKIE_AGE = 86400 * 365 * 10
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

127
PASSWORD_HASHERS = ('django.contrib.auth.hashers.BCryptSHA256PasswordHasher',)
Chris Lamb's avatar
Chris Lamb committed
128 129 130

AUTH_PASSWORD_VALIDATORS = (
    {
131
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'
Chris Lamb's avatar
Chris Lamb committed
132 133 134
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
135
        'OPTIONS': {'min_length': 6},
Chris Lamb's avatar
Chris Lamb committed
136 137
    },
    {
138
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'
Chris Lamb's avatar
Chris Lamb committed
139 140
    },
    {
141
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'
Chris Lamb's avatar
Chris Lamb committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    },
)

MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
        'KEY_PREFIX': 'bidb',
    }
}

# Always log to the console, even in production (ie. gunicorn)
LOGGING = copy.deepcopy(DEFAULT_LOGGING)
LOGGING['handlers']['console']['filters'] = []