config.py 6.04 KB
Newer Older
1
''' yes
Oliver Falk's avatar
Oliver Falk committed
2 3 4
Configuration overrides for settings.py
'''

Oliver Falk's avatar
Oliver Falk committed
5
import os
6
import sys
Oliver Falk's avatar
Oliver Falk committed
7
from django.urls import reverse_lazy
8 9
from django.utils.translation import ugettext_lazy as _
from django.contrib.messages import constants as message_constants
Oliver Falk's avatar
Oliver Falk committed
10
from ivatar.settings import BASE_DIR
Oliver Falk's avatar
Oliver Falk committed
11

12 13 14 15
from ivatar.settings import MIDDLEWARE
from ivatar.settings import INSTALLED_APPS
from ivatar.settings import TEMPLATES

Oliver Falk's avatar
Oliver Falk committed
16
ADMIN_USERS = []
17
ALLOWED_HOSTS = ['*']
Oliver Falk's avatar
Oliver Falk committed
18 19 20 21 22

INSTALLED_APPS.extend([
    'django_extensions',
    'django_openid_auth',
    'bootstrap4',
Oliver Falk's avatar
Oliver Falk committed
23
    'anymail',
Oliver Falk's avatar
Oliver Falk committed
24 25
    'ivatar',
    'ivatar.ivataraccount',
26
    'ivatar.tools',
Oliver Falk's avatar
Oliver Falk committed
27 28 29 30 31
])

MIDDLEWARE.extend([
    'django.middleware.locale.LocaleMiddleware',
])
32 33 34
MIDDLEWARE.insert(
    0, 'ivatar.middleware.MultipleProxyMiddleware',
)
Oliver Falk's avatar
Oliver Falk committed
35 36

AUTHENTICATION_BACKENDS = (
Oliver Falk's avatar
Oliver Falk committed
37 38
    # Enable this to allow LDAP authentication.
    # See INSTALL for more information.
Oliver Falk's avatar
Oliver Falk committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    # 'django_auth_ldap.backend.LDAPBackend',
    'django_openid_auth.auth.OpenIDBackend',
    'django.contrib.auth.backends.ModelBackend',
)

TEMPLATES[0]['DIRS'].extend([
    os.path.join(BASE_DIR, 'templates'),
])
TEMPLATES[0]['OPTIONS']['context_processors'].append(
    'ivatar.context_processors.basepage',
)

OPENID_CREATE_USERS = True
OPENID_UPDATE_DETAILS_FROM_SREG = True

54
SITE_NAME = os.environ.get('SITE_NAME', 'libravatar')
55
IVATAR_VERSION = '1.3'
Oliver Falk's avatar
Oliver Falk committed
56

57 58
SECURE_BASE_URL = os.environ.get('SECURE_BASE_URL', 'https://avatars.linux-kernel.at/avatar/')
BASE_URL = os.environ.get('BASE_URL', 'http://avatars.linux-kernel.at/avatar/')
59

Oliver Falk's avatar
Oliver Falk committed
60
LOGIN_REDIRECT_URL = reverse_lazy('profile')
Oliver Falk's avatar
Oliver Falk committed
61 62
MAX_LENGTH_EMAIL = 254  # http://stackoverflow.com/questions/386294

Oliver Falk's avatar
Oliver Falk committed
63
MAX_NUM_PHOTOS = 5
64
MAX_NUM_UNCONFIRMED_EMAILS = 5
Oliver Falk's avatar
Oliver Falk committed
65
MAX_PHOTO_SIZE = 10485760  # in bytes
Oliver Falk's avatar
Oliver Falk committed
66 67 68
MAX_PIXELS = 7000
AVATAR_MAX_SIZE = 512
JPEG_QUALITY = 85
Oliver Falk's avatar
Oliver Falk committed
69

70 71 72 73 74 75 76
# I'm not 100% sure if single character domains are possible
# under any tld... so MIN_LENGTH_EMAIL/_URL, might be +1
MIN_LENGTH_URL = 11  # eg. http://a.io
MAX_LENGTH_URL = 255  # MySQL can't handle more than that (LP: 1018682)
MIN_LENGTH_EMAIL = 6  # eg. x@x.xx
MAX_LENGTH_EMAIL = 254  # http://stackoverflow.com/questions/386294

77 78 79 80 81
BOOTSTRAP4 = {
    'include_jquery': False,
    'javascript_in_head': False,
    'css_url': {
        'href': '/static/css/bootstrap.min.css',
82 83
        'integrity':
            'sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB',
84 85 86 87 88 89 90 91 92
        'crossorigin': 'anonymous',
    },
    'javascript_url': {
        'url': '/static/js/bootstrap.min.js',
        'integrity': '',
        'crossorigin': 'anonymous',
    },
    'popper_url': {
        'url': '/static/js/popper.min.js',
93 94
        'integrity':
            'sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49',
95 96 97 98
        'crossorigin': 'anonymous',
    },
}

99
if 'EMAIL_BACKEND' in os.environ:
Oliver Falk's avatar
Oliver Falk committed
100
    EMAIL_BACKEND = os.environ['EMAIL_BACKEND']  # pragma: no cover
101 102 103 104
else:
    if 'test' in sys.argv or 'collectstatic' in sys.argv:
        EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
    else:
105 106 107 108 109 110 111 112
        try:
            ANYMAIL = {  # pragma: no cover
                'MAILGUN_API_KEY': os.environ['IVATAR_MAILGUN_API_KEY'],
                'MAILGUN_SENDER_DOMAIN': os.environ['IVATAR_MAILGUN_SENDER_DOMAIN'],
            }
            EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'  # pragma: no cover
        except Exception as exc:
            EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
113

114
SERVER_EMAIL = os.environ.get('SERVER_EMAIL', 'ivatar@mg.linux-kernel.at')
115
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'ivatar@mg.linux-kernel.at')
Oliver Falk's avatar
Oliver Falk committed
116 117 118

try:
    from ivatar.settings import DATABASES
Lars's avatar
Lars committed
119
except ImportError:  # pragma: no cover
Oliver Falk's avatar
Oliver Falk committed
120
    DATABASES = []  # pragma: no cover
clime's avatar
clime committed
121

Oliver Falk's avatar
Oliver Falk committed
122
if 'default' not in DATABASES:
Oliver Falk's avatar
Oliver Falk committed
123
    DATABASES['default'] = {  # pragma: no cover
Oliver Falk's avatar
Oliver Falk committed
124 125 126 127 128
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }

if 'MYSQL_DATABASE' in os.environ:
Oliver Falk's avatar
Oliver Falk committed
129
    DATABASES['default'] = {  # pragma: no cover
Oliver Falk's avatar
Oliver Falk committed
130 131 132 133 134 135 136
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.environ['MYSQL_DATABASE'],
        'USER': os.environ['MYSQL_USER'],
        'PASSWORD': os.environ['MYSQL_PASSWORD'],
        'HOST': 'mysql',
    }

clime's avatar
clime committed
137 138 139 140 141 142 143 144 145
if 'POSTGRESQL_DATABASE' in os.environ:
    DATABASES['default'] = {  # pragma: no cover
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.environ['POSTGRESQL_DATABASE'],
        'USER': os.environ['POSTGRESQL_USER'],
        'PASSWORD': os.environ['POSTGRESQL_PASSWORD'],
        'HOST': 'postgresql',
    }

146
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
147 148

USE_X_FORWARDED_HOST = True
149
ALLOWED_EXTERNAL_OPENID_REDIRECT_DOMAINS = ['avatars.linux-kernel.at', 'localhost',]
150 151

DEFAULT_AVATAR_SIZE = 80
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

LANGUAGES = (                                                                                                                                                 
  ('de', _('Deutsch')),
  ('en', _('English')),
  ('ca', _('Català')),
  ('cs', _('Česky')),
  ('es', _('Español')),
  ('eu', _('Basque')),
  ('fr', _('Français')),
  ('it', _('Italiano')),
  ('ja', _('日本語')),
  ('nl', _('Nederlands')),
  ('pt', _('Português')),
  ('ru', _('Русский')),
  ('sq', _('Shqip')),
  ('tr', _('Türkçe')),
  ('uk', _('Українська')),
)

MESSAGE_TAGS = {
  message_constants.DEBUG: 'debug',
  message_constants.INFO: 'info',
  message_constants.SUCCESS: 'success',
  message_constants.WARNING: 'warning',
  message_constants.ERROR: 'danger',
}
Oliver Falk's avatar
Oliver Falk committed
178 179 180 181 182 183 184

CACHES = {
  'default': {
    'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
    'LOCATION': [
        '127.0.0.1:11211',
    ],
185 186 187 188
  },
  'filesystem': {
    'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
    'LOCATION': '/var/tmp/ivatar_cache',
189
    'TIMEOUT': 900, # 15 minutes
Oliver Falk's avatar
Oliver Falk committed
190 191
  }
}
192

Oliver Falk's avatar
Oliver Falk committed
193
# This is 5 minutes caching for generated/resized images,
194
# so the sites don't hit ivatar so much - it's what's set in the HTTP header
Oliver Falk's avatar
Oliver Falk committed
195
CACHE_IMAGES_MAX_AGE = 5 * 60
196

197
CACHE_RESPONSE = True
198 199 200 201

# This MUST BE THE LAST!
if os.path.isfile(os.path.join(BASE_DIR, 'config_local.py')):
    from config_local import *  # noqa # flake8: noqa # NOQA # pragma: no cover