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/>.
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 def get_intOrNone(name
, default
):
33 """ Parses the env variable, accepts ints and literal None"""
34 value
= os
.getenv(name
, str(default
))
35 if value
.lower() == 'none':
40 DEBUG
= get_bool('DEBUG', False)
42 ADMINS
= re
.findall(r
'\s*([^<]+) <([^>]+)>\s*', os
.getenv('ADMINS', ''))
47 'default': dj_database_url
.config(
48 default
='postgres://mygpo:mygpo@localhost/mygpo'),
52 _cache_used
= bool(os
.getenv('CACHE_BACKEND', False))
59 'django.core.cache.backends.memcached.MemcachedCache'),
60 'LOCATION': os
.getenv('CACHE_LOCATION'),
64 # Local time zone for this installation. Choices can be found here:
65 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
66 # although not all choices may be available on all operating systems.
67 # If running in a Windows environment this must be set to the same as your
71 # Language code for this installation. All choices can be found here:
72 # http://www.i18nguy.com/unicode/language-identifiers.html
73 LANGUAGE_CODE
= 'en-us'
77 # If you set this to False, Django will make some optimizations so as not
78 # to load the internationalization machinery.
81 STATIC_ROOT
= 'staticfiles'
82 STATIC_URL
= '/media/'
85 os
.path
.abspath(os
.path
.join(BASE_DIR
, '..', 'htdocs', 'media')),
90 'BACKEND': 'django.template.backends.django.DjangoTemplates',
94 'context_processors': [
95 'django.contrib.auth.context_processors.auth',
96 'django.template.context_processors.debug',
97 'django.template.context_processors.i18n',
98 'django.template.context_processors.media',
99 'django.template.context_processors.static',
100 'django.template.context_processors.tz',
101 'django.contrib.messages.context_processors.messages',
102 'mygpo.web.google.analytics',
103 'mygpo.web.google.adsense',
104 # make the debug variable available in templates
105 # https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-debug
106 'django.core.context_processors.debug',
108 # required so that the request obj can be accessed from
109 # templates. this is used to direct users to previous
111 'django.core.context_processors.request',
114 ('django.template.loaders.cached.Loader', [
115 'django.template.loaders.app_directories.Loader',
122 MIDDLEWARE_CLASSES
= (
123 'django.middleware.common.CommonMiddleware',
124 'django.middleware.csrf.CsrfViewMiddleware',
125 'django.contrib.sessions.middleware.SessionMiddleware',
126 'django.contrib.auth.middleware.AuthenticationMiddleware',
127 'django.middleware.locale.LocaleMiddleware',
128 'django.contrib.messages.middleware.MessageMiddleware',
131 ROOT_URLCONF
= 'mygpo.urls'
134 'django.contrib.contenttypes',
135 'django.contrib.messages',
136 'django.contrib.admin',
137 'django.contrib.humanize',
138 'django.contrib.auth',
139 'django.contrib.sessions',
140 'django.contrib.staticfiles',
141 'django.contrib.sites',
151 'mygpo.subscriptions',
154 'mygpo.usersettings',
160 'mygpo.episodestates',
163 'mygpo.administration',
165 'mygpo.podcastlists',
171 INSTALLED_APPS
+= ('debug_toolbar', )
172 MIDDLEWARE_CLASSES
+= ('debug_toolbar.middleware.DebugToolbarMiddleware', )
182 INSTALLED_APPS
+= ('opbeat.contrib.django', )
184 # add opbeat middleware to the beginning of the middleware classes list
185 MIDDLEWARE_CLASSES
= \
186 ('opbeat.contrib.django.middleware.OpbeatAPMMiddleware',) + \
193 ACCOUNT_ACTIVATION_DAYS
= int(os
.getenv('ACCOUNT_ACTIVATION_DAYS', 7))
195 AUTHENTICATION_BACKENDS
= (
196 'mygpo.users.backend.CaseInsensitiveModelBackend',
197 'mygpo.web.auth.EmailAuthenticationBackend',
200 SESSION_ENGINE
= "django.contrib.sessions.backends.cached_db"
202 # TODO: use (default) JSON serializer for security
203 # this would currently fail as we're (de)serializing datetime objects
204 # https://docs.djangoproject.com/en/1.5/topics/http/sessions/#session-serialization
205 SESSION_SERIALIZER
= 'django.contrib.sessions.serializers.PickleSerializer'
208 MESSAGE_STORAGE
= 'django.contrib.messages.storage.session.SessionStorage'
210 USER_CLASS
= 'mygpo.users.models.User'
212 LOGIN_URL
= '/login/'
214 CSRF_FAILURE_VIEW
= 'mygpo.web.views.csrf_failure'
217 DEFAULT_FROM_EMAIL
= os
.getenv('DEFAULT_FROM_EMAIL', '')
219 SECRET_KEY
= os
.getenv('SECRET_KEY', '')
221 if 'test' in sys
.argv
:
224 GOOGLE_ANALYTICS_PROPERTY_ID
= os
.getenv('GOOGLE_ANALYTICS_PROPERTY_ID', '')
226 DIRECTORY_EXCLUDED_TAGS
= os
.getenv('DIRECTORY_EXCLUDED_TAGS', '').split()
228 FLICKR_API_KEY
= os
.getenv('FLICKR_API_KEY', '')
230 SOUNDCLOUD_CONSUMER_KEY
= os
.getenv('SOUNDCLOUD_CONSUMER_KEY', '')
232 MAINTENANCE
= get_bool('MAINTENANCE', False)
235 ALLOWED_HOSTS
= ['*']
240 'disable_existing_loggers': False,
243 'format': '%(asctime)s %(name)s %(levelname)s %(message)s',
247 'require_debug_false': {
248 '()': 'django.utils.log.RequireDebugFalse'
253 'level': os
.getenv('LOGGING_CONSOLE_LEVEL', 'DEBUG'),
254 'class': 'logging.StreamHandler',
255 'formatter': 'verbose',
259 'filters': ['require_debug_false'],
260 'class': 'django.utils.log.AdminEmailHandler',
265 'handlers': os
.getenv('LOGGING_DJANGO_HANDLERS',
268 'level': os
.getenv('LOGGING_DJANGO_LEVEL', 'WARN'),
271 'handlers': os
.getenv('LOGGING_MYGPO_HANDLERS', 'console').split(),
272 'level': os
.getenv('LOGGING_MYGPO_LEVEL', 'INFO'),
275 'handlers': os
.getenv('LOGGING_CELERY_HANDLERS',
277 'level': os
.getenv('LOGGING_CELERY_LEVEL', 'DEBUG'),
282 _use_log_file
= bool(os
.getenv('LOGGING_FILENAME', False))
285 LOGGING
['handlers']['file'] = {
287 'class': 'logging.handlers.RotatingFileHandler',
288 'filename': os
.getenv('LOGGING_FILENAME'),
289 'maxBytes': 10000000,
291 'formatter': 'verbose',
295 # minimum number of subscribers a podcast must have to be assigned a slug
296 PODCAST_SLUG_SUBSCRIBER_LIMIT
= int(os
.getenv(
297 'PODCAST_SLUG_SUBSCRIBER_LIMIT', 10))
299 # minimum number of subscribers that a podcast needs to "push" one of its
300 # categories to the top
301 MIN_SUBSCRIBERS_CATEGORY
= int(os
.getenv('MIN_SUBSCRIBERS_CATEGORY', 10))
303 # maximum number of episode actions that the API processes immediatelly before
304 # returning the response. Larger requests will be handled in background.
305 # Handler can be set to None to disable
306 API_ACTIONS_MAX_NONBG
= int(os
.getenv('API_ACTIONS_MAX_NONBG', 100))
307 API_ACTIONS_BG_HANDLER
= 'mygpo.api.tasks.episode_actions_celery_handler'
310 ADSENSE_CLIENT
= os
.getenv('ADSENSE_CLIENT', '')
312 ADSENSE_SLOT_BOTTOM
= os
.getenv('ADSENSE_SLOT_BOTTOM', '')
314 # we're running behind a proxy that sets the X-Forwarded-Proto header correctly
315 # see https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
316 SECURE_PROXY_SSL_HEADER
= ('HTTP_X_FORWARDED_PROTO', 'https')
319 # enabled access to staff-only areas with ?staff=<STAFF_TOKEN>
320 STAFF_TOKEN
= os
.getenv('STAFF_TOKEN', None)
322 # Flattr settings -- available after you register your app
323 FLATTR_KEY
= os
.getenv('FLATTR_KEY', '')
324 FLATTR_SECRET
= os
.getenv('FLATTR_SECRET', '')
326 # Flattr thing of the webservice. Will be flattr'd when a user sets
327 # the "Auto-Flattr gpodder.net" option
328 FLATTR_MYGPO_THING
= os
.getenv(
329 'FLATTR_MYGPO_THING',
330 'https://flattr.com/submit/auto?user_id=stefankoegl&url=http://gpodder.net'
333 # The User-Agent string used for outgoing HTTP requests
334 USER_AGENT
= 'gpodder.net (+https://github.com/gpodder/mygpo)'
336 # Base URL of the website that is used if the actually used parameters is not
337 # available. Request handlers, for example, can access the requested domain.
338 # Code that runs in background can not do this, and therefore requires a
339 # default value. This should be set to something like 'http://example.com'
340 DEFAULT_BASE_URL
= os
.getenv('DEFAULT_BASE_URL', '')
345 BROKER_URL
= os
.getenv('BROKER_URL', 'redis://localhost')
346 CELERY_RESULT_BACKEND
= 'djcelery.backends.database:DatabaseBackend'
348 SERVER_EMAIL
= os
.getenv('SERVER_EMAIL', 'no-reply@example.com')
350 CELERY_TASK_RESULT_EXPIRES
= 60 * 60 # 1h expiry time in seconds
352 CELERY_ACCEPT_CONTENT
= ['pickle', 'json']
354 CELERY_SEND_TASK_ERROR_EMAILS
= get_bool('CELERY_SEND_TASK_ERROR_EMAILS',
357 BROKER_POOL_LIMIT
= get_intOrNone('BROKER_POOL_LIMIT', 10)
361 GOOGLE_CLIENT_ID
= os
.getenv('GOOGLE_CLIENT_ID', '')
362 GOOGLE_CLIENT_SECRET
= os
.getenv('GOOGLE_CLIENT_SECRET', '')
364 # URL where users of the site can get support
365 SUPPORT_URL
= os
.getenv('SUPPORT_URL', '')
368 FEEDSERVICE_URL
= os
.getenv('FEEDSERVICE_URL', 'http://feeds.gpodder.net/')
370 # Elasticsearch settings
372 ELASTICSEARCH_SERVER
= os
.getenv('ELASTICSEARCH_SERVER', '127.0.0.1:9200')
373 ELASTICSEARCH_INDEX
= os
.getenv('ELASTICSEARCH_INDEX', 'mygpo')
374 ELASTICSEARCH_TIMEOUT
= float(os
.getenv('ELASTICSEARCH_TIMEOUT', '2'))
376 # time for how long an activation is valid; after that, an unactivated user
378 ACTIVATION_VALID_DAYS
= int(os
.getenv('ACTIVATION_VALID_DAYS', 10))
382 "ORGANIZATION_ID": os
.getenv('OPBEAT_ORGANIZATION_ID', ''),
383 "APP_ID": os
.getenv('OPBEAT_APP_ID', ''),
384 "SECRET_TOKEN": os
.getenv('OPBEAT_SECRET_TOKEN', ''),
388 INTERNAL_IPS
= os
.getenv('INTERNAL_IPS', '').split()
390 EMAIL_BACKEND
= os
.getenv('EMAIL_BACKEND',
391 'django.core.mail.backends.smtp.EmailBackend')
393 PODCAST_AD_ID
= os
.getenv('PODCAST_AD_ID')