[Users] active case-insensitive login
[mygpo.git] / mygpo / settings.py
blobd3041567afacfc8e7dffc6d2b78508ee1224e11f
1 # Django settings for mygpo project.
3 # This file is part of my.gpodder.org.
5 # my.gpodder.org is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or (at your
8 # option) any later version.
10 # my.gpodder.org is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
13 # License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
19 import re
20 import sys
21 import os.path
22 import dj_database_url
25 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
28 def get_bool(name, default):
29 return os.getenv(name, str(default)).lower() == 'true'
32 DEBUG = get_bool('DEBUG', False)
34 ADMINS = re.findall(r'\s*([^<]+) <([^>]+)>\s*', os.getenv('ADMINS', ''))
36 MANAGERS = ADMINS
38 DATABASES = {
39 'default': dj_database_url.config(
40 default='postgres://mygpo:mygpo@localhost/mygpo'),
44 _cache_used = bool(os.getenv('CACHE_BACKEND', False))
46 if _cache_used:
47 CACHES = {}
48 CACHES['default'] = {
49 'BACKEND': os.getenv(
50 'CACHE_BACKEND',
51 'django.core.cache.backends.memcached.MemcachedCache'),
52 'LOCATION': os.getenv('CACHE_LOCATION'),
56 # Local time zone for this installation. Choices can be found here:
57 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
58 # although not all choices may be available on all operating systems.
59 # If running in a Windows environment this must be set to the same as your
60 # system time zone.
61 TIME_ZONE = 'UTC'
63 # Language code for this installation. All choices can be found here:
64 # http://www.i18nguy.com/unicode/language-identifiers.html
65 LANGUAGE_CODE = 'en-us'
67 SITE_ID = 1
69 # If you set this to False, Django will make some optimizations so as not
70 # to load the internationalization machinery.
71 USE_I18N = True
73 STATIC_ROOT = 'staticfiles'
74 STATIC_URL = '/media/'
76 STATICFILES_DIRS = (
77 os.path.abspath(os.path.join(BASE_DIR, '..', 'htdocs', 'media')),
81 TEMPLATES = [{
82 'BACKEND': 'django.template.backends.django.DjangoTemplates',
83 'DIRS': [],
84 'OPTIONS': {
85 'context_processors': [
86 'django.contrib.auth.context_processors.auth',
87 'django.template.context_processors.debug',
88 'django.template.context_processors.i18n',
89 'django.template.context_processors.media',
90 'django.template.context_processors.static',
91 'django.template.context_processors.tz',
92 'django.contrib.messages.context_processors.messages',
93 'mygpo.web.google.analytics',
94 'mygpo.web.google.adsense',
95 # make the debug variable available in templates
96 # https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-debug
97 'django.core.context_processors.debug',
99 # required so that the request obj can be accessed from
100 # templates. this is used to direct users to previous
101 # page after login
102 'django.core.context_processors.request',
104 'loaders': [
105 ('django.template.loaders.cached.Loader', [
106 'django.template.loaders.app_directories.Loader',
113 MIDDLEWARE_CLASSES = (
114 'django.middleware.common.CommonMiddleware',
115 'django.middleware.csrf.CsrfViewMiddleware',
116 'django.contrib.sessions.middleware.SessionMiddleware',
117 'django.contrib.auth.middleware.AuthenticationMiddleware',
118 'django.middleware.locale.LocaleMiddleware',
119 'django.contrib.messages.middleware.MessageMiddleware',
122 ROOT_URLCONF = 'mygpo.urls'
124 INSTALLED_APPS = (
125 'django.contrib.contenttypes',
126 'django.contrib.messages',
127 'django.contrib.admin',
128 'django.contrib.humanize',
129 'django.contrib.auth',
130 'django.contrib.sessions',
131 'django.contrib.staticfiles',
132 'django.contrib.sites',
133 'djcelery',
134 'mygpo.core',
135 'mygpo.podcasts',
136 'mygpo.chapters',
137 'mygpo.search',
138 'mygpo.users',
139 'mygpo.api',
140 'mygpo.web',
141 'mygpo.publisher',
142 'mygpo.subscriptions',
143 'mygpo.history',
144 'mygpo.favorites',
145 'mygpo.usersettings',
146 'mygpo.data',
147 'mygpo.userfeeds',
148 'mygpo.suggestions',
149 'mygpo.directory',
150 'mygpo.categories',
151 'mygpo.episodestates',
152 'mygpo.maintenance',
153 'mygpo.share',
154 'mygpo.administration',
155 'mygpo.pubsub',
156 'mygpo.podcastlists',
157 'mygpo.votes',
160 try:
161 import debug_toolbar
162 INSTALLED_APPS += ('debug_toolbar', )
164 except ImportError:
165 pass
168 try:
169 import opbeat
170 INSTALLED_APPS += ('opbeat.contrib.django', )
172 # add opbeat middleware to the beginning of the middleware classes list
173 MIDDLEWARE_CLASSES = \
174 ('opbeat.contrib.django.middleware.OpbeatAPMMiddleware',) + \
175 MIDDLEWARE_CLASSES
177 except ImportError:
178 pass
181 ACCOUNT_ACTIVATION_DAYS = int(os.getenv('ACCOUNT_ACTIVATION_DAYS', 7))
183 AUTHENTICATION_BACKENDS = (
184 'mygpo.users.backend.CaseInsensitiveModelBackend',
185 'mygpo.web.auth.EmailAuthenticationBackend',
188 SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
190 # TODO: use (default) JSON serializer for security
191 # this would currently fail as we're (de)serializing datetime objects
192 # https://docs.djangoproject.com/en/1.5/topics/http/sessions/#session-serialization
193 SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
196 MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
198 USER_CLASS = 'mygpo.users.models.User'
200 LOGIN_URL = '/login/'
202 CSRF_FAILURE_VIEW = 'mygpo.web.views.security.csrf_failure'
205 DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', '')
207 SECRET_KEY = os.getenv('SECRET_KEY', '')
209 if 'test' in sys.argv:
210 SECRET_KEY = 'test'
212 GOOGLE_ANALYTICS_PROPERTY_ID = os.getenv('GOOGLE_ANALYTICS_PROPERTY_ID', '')
214 DIRECTORY_EXCLUDED_TAGS = os.getenv('DIRECTORY_EXCLUDED_TAGS', '').split()
216 FLICKR_API_KEY = os.getenv('FLICKR_API_KEY', '')
218 SOUNDCLOUD_CONSUMER_KEY = os.getenv('SOUNDCLOUD_CONSUMER_KEY', '')
220 MAINTENANCE = get_bool('MAINTENANCE', False)
223 ALLOWED_HOSTS = ['*']
226 LOGGING = {
227 'version': 1,
228 'disable_existing_loggers': False,
229 'formatters': {
230 'verbose': {
231 'format': '%(asctime)s %(name)s %(levelname)s %(message)s',
234 'filters': {
235 'require_debug_false': {
236 '()': 'django.utils.log.RequireDebugFalse'
239 'handlers': {
240 'console': {
241 'level': os.getenv('LOGGING_CONSOLE_LEVEL', 'DEBUG'),
242 'class': 'logging.StreamHandler',
243 'formatter': 'verbose',
245 'mail_admins': {
246 'level': 'ERROR',
247 'filters': ['require_debug_false'],
248 'class': 'django.utils.log.AdminEmailHandler',
251 'loggers': {
252 'django': {
253 'handlers': os.getenv('LOGGING_DJANGO_HANDLERS',
254 'console').split(),
255 'propagate': True,
256 'level': os.getenv('LOGGING_DJANGO_LEVEL', 'WARN'),
258 'mygpo': {
259 'handlers': os.getenv('LOGGING_MYGPO_HANDLERS', 'console').split(),
260 'level': os.getenv('LOGGING_MYGPO_LEVEL', 'INFO'),
262 'celery': {
263 'handlers': os.getenv('LOGGING_CELERY_HANDLERS',
264 'console').split(),
265 'level': os.getenv('LOGGING_CELERY_LEVEL', 'DEBUG'),
270 _use_log_file = bool(os.getenv('LOGGING_FILENAME', False))
272 if _use_log_file:
273 LOGGING['handlers']['file'] = {
274 'level': 'INFO',
275 'class': 'logging.handlers.RotatingFileHandler',
276 'filename': os.getenv('LOGGING_FILENAME'),
277 'maxBytes': 10000000,
278 'backupCount': 10,
279 'formatter': 'verbose',
283 # minimum number of subscribers a podcast must have to be assigned a slug
284 PODCAST_SLUG_SUBSCRIBER_LIMIT = int(os.getenv(
285 'PODCAST_SLUG_SUBSCRIBER_LIMIT', 10))
287 # minimum number of subscribers that a podcast needs to "push" one of its
288 # categories to the top
289 MIN_SUBSCRIBERS_CATEGORY = int(os.getenv('MIN_SUBSCRIBERS_CATEGORY', 10))
291 # maximum number of episode actions that the API processes immediatelly before
292 # returning the response. Larger requests will be handled in background.
293 # Handler can be set to None to disable
294 API_ACTIONS_MAX_NONBG = int(os.getenv('API_ACTIONS_MAX_NONBG', 100))
295 API_ACTIONS_BG_HANDLER = 'mygpo.api.tasks.episode_actions_celery_handler'
298 ADSENSE_CLIENT = os.getenv('ADSENSE_CLIENT', '')
300 ADSENSE_SLOT_BOTTOM = os.getenv('ADSENSE_SLOT_BOTTOM', '')
302 # we're running behind a proxy that sets the X-Forwarded-Proto header correctly
303 # see https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
304 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
307 # enabled access to staff-only areas with ?staff=<STAFF_TOKEN>
308 STAFF_TOKEN = os.getenv('STAFF_TOKEN', None)
310 # Flattr settings -- available after you register your app
311 FLATTR_KEY = os.getenv('FLATTR_KEY', '')
312 FLATTR_SECRET = os.getenv('FLATTR_SECRET', '')
314 # Flattr thing of the webservice. Will be flattr'd when a user sets
315 # the "Auto-Flattr gpodder.net" option
316 FLATTR_MYGPO_THING = os.getenv(
317 'FLATTR_MYGPO_THING',
318 'https://flattr.com/submit/auto?user_id=stefankoegl&url=http://gpodder.net'
321 # The User-Agent string used for outgoing HTTP requests
322 USER_AGENT = 'gpodder.net (+https://github.com/gpodder/mygpo)'
324 # Base URL of the website that is used if the actually used parameters is not
325 # available. Request handlers, for example, can access the requested domain.
326 # Code that runs in background can not do this, and therefore requires a
327 # default value. This should be set to something like 'http://example.com'
328 DEFAULT_BASE_URL = os.getenv('DEFAULT_BASE_URL', '')
331 ### Celery
333 BROKER_URL = os.getenv('BROKER_URL', 'redis://localhost')
334 CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
336 SERVER_EMAIL = os.getenv('SERVER_EMAIL', 'no-reply@example.com')
338 CELERY_TASK_RESULT_EXPIRES = 60 * 60 # 1h expiry time in seconds
340 CELERY_ACCEPT_CONTENT = ['pickle', 'json']
342 CELERY_SEND_TASK_ERROR_EMAILS = get_bool('CELERY_SEND_TASK_ERROR_EMAILS',
343 False)
345 ### Google API
347 GOOGLE_CLIENT_ID = os.getenv('GOOGLE_CLIENT_ID', '')
348 GOOGLE_CLIENT_SECRET = os.getenv('GOOGLE_CLIENT_SECRET', '')
350 # URL where users of the site can get support
351 SUPPORT_URL = os.getenv('SUPPORT_URL', '')
354 FEEDSERVICE_URL = os.getenv('FEEDSERVICE_URL', 'http://feeds.gpodder.net/')
356 # Elasticsearch settings
358 ELASTICSEARCH_SERVER = os.getenv('ELASTICSEARCH_SERVER', '127.0.0.1:9200')
359 ELASTICSEARCH_INDEX = os.getenv('ELASTICSEARCH_INDEX', 'mygpo')
360 ELASTICSEARCH_TIMEOUT = float(os.getenv('ELASTICSEARCH_TIMEOUT', '2'))
362 # time for how long an activation is valid; after that, an unactivated user
363 # will be deleted
364 ACTIVATION_VALID_DAYS = int(os.getenv('ACTIVATION_VALID_DAYS', 10))
367 OPBEAT = {
368 "ORGANIZATION_ID": os.getenv('OPBEAT_ORGANIZATION_ID', ''),
369 "APP_ID": os.getenv('OPBEAT_APP_ID', ''),
370 "SECRET_TOKEN": os.getenv('OPBEAT_SECRET_TOKEN', ''),
374 INTERNAL_IPS = os.getenv('INTERNAL_IPS', '').split()
376 EMAIL_BACKEND = os.getenv('EMAIL_BACKEND',
377 'django.core.mail.backends.smtp.EmailBackend')