Import GenericForeignKey from new path
[mygpo.git] / mygpo / settings.py
blobe1c5834cfe50874e138b6b505b3768272f309c89
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 TEMPLATE_DEBUG = DEBUG
36 ADMINS = re.findall(r'\s*([^<]+) <([^>]+)>\s*', os.getenv('ADMINS', ''))
38 MANAGERS = ADMINS
40 DATABASES = {
41 'default': dj_database_url.config(
42 default='postgres://mygpo:mygpo@localhost/mygpo'),
46 _cache_used = bool(os.getenv('CACHE_BACKEND', False))
48 if _cache_used:
49 CACHES = {}
50 CACHES['default'] = {
51 'BACKEND': os.getenv(
52 'CACHE_BACKEND',
53 'django.core.cache.backends.memcached.MemcachedCache'),
54 'LOCATION': os.getenv('CACHE_LOCATION'),
58 # Local time zone for this installation. Choices can be found here:
59 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
60 # although not all choices may be available on all operating systems.
61 # If running in a Windows environment this must be set to the same as your
62 # system time zone.
63 TIME_ZONE = 'UTC'
65 # Language code for this installation. All choices can be found here:
66 # http://www.i18nguy.com/unicode/language-identifiers.html
67 LANGUAGE_CODE = 'en-us'
69 SITE_ID = 1
71 # If you set this to False, Django will make some optimizations so as not
72 # to load the internationalization machinery.
73 USE_I18N = True
75 STATIC_ROOT = 'staticfiles'
76 STATIC_URL = '/media/'
78 STATICFILES_DIRS = (
79 os.path.abspath(os.path.join(BASE_DIR, '..', 'htdocs', 'media')),
82 # List of callables that know how to import templates from various sources.
83 TEMPLATE_LOADERS = (
84 ('django.template.loaders.cached.Loader', (
85 'django.template.loaders.app_directories.Loader',
86 )),
89 MIDDLEWARE_CLASSES = (
90 'django.middleware.common.CommonMiddleware',
91 'django.middleware.csrf.CsrfViewMiddleware',
92 'django.contrib.sessions.middleware.SessionMiddleware',
93 'django.contrib.auth.middleware.AuthenticationMiddleware',
94 'django.middleware.locale.LocaleMiddleware',
95 'django.contrib.messages.middleware.MessageMiddleware',
98 ROOT_URLCONF = 'mygpo.urls'
100 TEMPLATE_DIRS = ()
102 INSTALLED_APPS = (
103 'django.contrib.contenttypes',
104 'django.contrib.messages',
105 'django.contrib.admin',
106 'django.contrib.humanize',
107 'django.contrib.auth',
108 'django.contrib.sessions',
109 'django.contrib.staticfiles',
110 'django.contrib.sites',
111 'djcelery',
112 'mygpo.core',
113 'mygpo.podcasts',
114 'mygpo.chapters',
115 'mygpo.search',
116 'mygpo.users',
117 'mygpo.api',
118 'mygpo.web',
119 'mygpo.publisher',
120 'mygpo.subscriptions',
121 'mygpo.history',
122 'mygpo.favorites',
123 'mygpo.usersettings',
124 'mygpo.data',
125 'mygpo.userfeeds',
126 'mygpo.suggestions',
127 'mygpo.directory',
128 'mygpo.categories',
129 'mygpo.episodestates',
130 'mygpo.maintenance',
131 'mygpo.share',
132 'mygpo.administration',
133 'mygpo.pubsub',
134 'mygpo.podcastlists',
135 'mygpo.votes',
138 try:
139 import debug_toolbar
140 INSTALLED_APPS += ('debug_toolbar', )
142 except ImportError:
143 pass
146 try:
147 import opbeat
148 INSTALLED_APPS += ('opbeat.contrib.django', )
150 # add opbeat middleware to the beginning of the middleware classes list
151 MIDDLEWARE_CLASSES = \
152 ('opbeat.contrib.django.middleware.OpbeatAPMMiddleware',) + \
153 MIDDLEWARE_CLASSES
155 except ImportError:
156 pass
159 ACCOUNT_ACTIVATION_DAYS = int(os.getenv('ACCOUNT_ACTIVATION_DAYS', 7))
161 AUTHENTICATION_BACKENDS = (
162 'django.contrib.auth.backends.ModelBackend',
163 'mygpo.web.auth.EmailAuthenticationBackend',
166 SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
168 # TODO: use (default) JSON serializer for security
169 # this would currently fail as we're (de)serializing datetime objects
170 # https://docs.djangoproject.com/en/1.5/topics/http/sessions/#session-serialization
171 SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
174 from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
176 TEMPLATE_CONTEXT_PROCESSORS += (
177 "mygpo.web.google.analytics",
178 "mygpo.web.google.adsense",
180 # make the debug variable available in templates
181 # https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-debug
182 "django.core.context_processors.debug",
184 # required so that the request obj can be accessed from templates.
185 # this is used to direct users to previous page after login
186 'django.core.context_processors.request',
189 MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
191 USER_CLASS = 'mygpo.users.models.User'
193 LOGIN_URL = '/login/'
195 CSRF_FAILURE_VIEW = 'mygpo.web.views.security.csrf_failure'
198 DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', '')
200 SECRET_KEY = os.getenv('SECRET_KEY', '')
202 if 'test' in sys.argv:
203 SECRET_KEY = 'test'
205 GOOGLE_ANALYTICS_PROPERTY_ID = os.getenv('GOOGLE_ANALYTICS_PROPERTY_ID', '')
207 DIRECTORY_EXCLUDED_TAGS = os.getenv('DIRECTORY_EXCLUDED_TAGS', '').split()
209 FLICKR_API_KEY = os.getenv('FLICKR_API_KEY', '')
211 SOUNDCLOUD_CONSUMER_KEY = os.getenv('SOUNDCLOUD_CONSUMER_KEY', '')
213 MAINTENANCE = get_bool('MAINTENANCE', False)
216 ALLOWED_HOSTS = ['*']
219 LOGGING = {
220 'version': 1,
221 'disable_existing_loggers': False,
222 'formatters': {
223 'verbose': {
224 'format': '%(asctime)s %(name)s %(levelname)s %(message)s',
227 'filters': {
228 'require_debug_false': {
229 '()': 'django.utils.log.RequireDebugFalse'
232 'handlers': {
233 'console': {
234 'level': os.getenv('LOGGING_CONSOLE_LEVEL', 'DEBUG'),
235 'class': 'logging.StreamHandler',
236 'formatter': 'verbose',
238 'mail_admins': {
239 'level': 'ERROR',
240 'filters': ['require_debug_false'],
241 'class': 'django.utils.log.AdminEmailHandler',
244 'loggers': {
245 'django': {
246 'handlers': os.getenv('LOGGING_DJANGO_HANDLERS',
247 'console').split(),
248 'propagate': True,
249 'level': os.getenv('LOGGING_DJANGO_LEVEL', 'WARN'),
251 'mygpo': {
252 'handlers': os.getenv('LOGGING_MYGPO_HANDLERS', 'console').split(),
253 'level': os.getenv('LOGGING_MYGPO_LEVEL', 'INFO'),
255 'celery': {
256 'handlers': os.getenv('LOGGING_CELERY_HANDLERS',
257 'console').split(),
258 'level': os.getenv('LOGGING_CELERY_LEVEL', 'DEBUG'),
263 _use_log_file = bool(os.getenv('LOGGING_FILENAME', False))
265 if _use_log_file:
266 LOGGING['handlers']['file'] = {
267 'level': 'INFO',
268 'class': 'logging.handlers.RotatingFileHandler',
269 'filename': os.getenv('LOGGING_FILENAME'),
270 'maxBytes': 10000000,
271 'backupCount': 10,
272 'formatter': 'verbose',
276 # minimum number of subscribers a podcast must have to be assigned a slug
277 PODCAST_SLUG_SUBSCRIBER_LIMIT = int(os.getenv(
278 'PODCAST_SLUG_SUBSCRIBER_LIMIT', 10))
280 # minimum number of subscribers that a podcast needs to "push" one of its
281 # categories to the top
282 MIN_SUBSCRIBERS_CATEGORY = int(os.getenv('MIN_SUBSCRIBERS_CATEGORY', 10))
284 # maximum number of episode actions that the API processes immediatelly before
285 # returning the response. Larger requests will be handled in background.
286 # Handler can be set to None to disable
287 API_ACTIONS_MAX_NONBG = int(os.getenv('API_ACTIONS_MAX_NONBG', 100))
288 API_ACTIONS_BG_HANDLER = 'mygpo.api.tasks.episode_actions_celery_handler'
291 ADSENSE_CLIENT = os.getenv('ADSENSE_CLIENT', '')
293 ADSENSE_SLOT_BOTTOM = os.getenv('ADSENSE_SLOT_BOTTOM', '')
295 # we're running behind a proxy that sets the X-Forwarded-Proto header correctly
296 # see https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
297 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
300 # enabled access to staff-only areas with ?staff=<STAFF_TOKEN>
301 STAFF_TOKEN = os.getenv('STAFF_TOKEN', None)
303 # Flattr settings -- available after you register your app
304 FLATTR_KEY = os.getenv('FLATTR_KEY', '')
305 FLATTR_SECRET = os.getenv('FLATTR_SECRET', '')
307 # Flattr thing of the webservice. Will be flattr'd when a user sets
308 # the "Auto-Flattr gpodder.net" option
309 FLATTR_MYGPO_THING = os.getenv(
310 'FLATTR_MYGPO_THING',
311 'https://flattr.com/submit/auto?user_id=stefankoegl&url=http://gpodder.net'
314 # The User-Agent string used for outgoing HTTP requests
315 USER_AGENT = 'gpodder.net (+https://github.com/gpodder/mygpo)'
317 # Base URL of the website that is used if the actually used parameters is not
318 # available. Request handlers, for example, can access the requested domain.
319 # Code that runs in background can not do this, and therefore requires a
320 # default value. This should be set to something like 'http://example.com'
321 DEFAULT_BASE_URL = os.getenv('DEFAULT_BASE_URL', '')
324 ### Celery
326 BROKER_URL = os.getenv('BROKER_URL', 'redis://localhost')
327 CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
329 SERVER_EMAIL = os.getenv('SERVER_EMAIL', 'no-reply@example.com')
331 CELERY_TASK_RESULT_EXPIRES = 60 * 60 # 1h expiry time in seconds
333 CELERY_ACCEPT_CONTENT = ['pickle', 'json']
335 CELERY_SEND_TASK_ERROR_EMAILS = get_bool('CELERY_SEND_TASK_ERROR_EMAILS',
336 False)
338 ### Google API
340 GOOGLE_CLIENT_ID = os.getenv('GOOGLE_CLIENT_ID', '')
341 GOOGLE_CLIENT_SECRET = os.getenv('GOOGLE_CLIENT_SECRET', '')
343 # URL where users of the site can get support
344 SUPPORT_URL = os.getenv('SUPPORT_URL', '')
347 FEEDSERVICE_URL = os.getenv('FEEDSERVICE_URL', 'http://feeds.gpodder.net/')
349 # Elasticsearch settings
351 ELASTICSEARCH_SERVER = os.getenv('ELASTICSEARCH_SERVER', '127.0.0.1:9200')
352 ELASTICSEARCH_INDEX = os.getenv('ELASTICSEARCH_INDEX', 'mygpo')
353 ELASTICSEARCH_TIMEOUT = float(os.getenv('ELASTICSEARCH_TIMEOUT', '2'))
355 # time for how long an activation is valid; after that, an unactivated user
356 # will be deleted
357 ACTIVATION_VALID_DAYS = int(os.getenv('ACTIVATION_VALID_DAYS', 10))
360 OPBEAT = {
361 "ORGANIZATION_ID": os.getenv('OPBEAT_ORGANIZATION_ID', ''),
362 "APP_ID": os.getenv('OPBEAT_APP_ID', ''),
363 "SECRET_TOKEN": os.getenv('OPBEAT_SECRET_TOKEN', ''),
367 INTERNAL_IPS = os.getenv('INTERNAL_IPS', '').split()
369 EMAIL_BACKEND = os.getenv('EMAIL_BACKEND',
370 'django.core.mail.backends.smtp.EmailBackend')