Start Docker support [WIP]
[mygpo.git] / mygpo / settings.py
blobaa42797dbe6322aeb8e495fcad95245d0ec1f351
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 sys
20 import os.path
21 import dj_database_url
24 def parse_bool(s):
25 """ parses a boolean setting """
26 if isinstance(s, bool):
27 return s
28 s = s.lower.strip()
29 return s not in ('n', 'no', 'false', '0', 'off')
32 def parse_int(s):
33 return int(str(s))
36 def parse_strlist(s):
37 return [item.strip() for item in s.split(',')]
40 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
42 # http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#ChangedthewayURLpathsaredetermined
43 FORCE_SCRIPT_NAME = ""
45 DEBUG = parse_bool(os.getenv('DEBUG', True))
46 TEMPLATE_DEBUG = DEBUG
48 ADMINS = ()
50 MANAGERS = ADMINS
52 DATABASES = {
53 'default': dj_database_url.config(
54 default='postgres://mygpo:mygpo@localhost/mygpo'),
57 COUCHDB_DATABASES = {
58 'mygpo.users':
59 {'URL': 'http://127.0.0.1:5984/mygpo_users'},
61 'mygpo.userdata':
62 {'URL': 'http://127.0.0.1:5984/mygpo_userdata'},
65 # Maps design documents to databases. The keys correspond to the directories in
66 # mygpo/couch/, the values are the app labels which are mapped to the actual
67 # databases in COUCHDB_DATABASES. This indirect mapping is used because
68 # COUCHDB_DATABASES is likely to be overwritten in settings_prod.py while
69 # COUCHDB_DDOC_MAPPING is most probably not overwritten.
70 COUCHDB_DDOC_MAPPING = {
71 'userdata': 'userdata',
72 'users': 'users',
75 # Local time zone for this installation. Choices can be found here:
76 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
77 # although not all choices may be available on all operating systems.
78 # If running in a Windows environment this must be set to the same as your
79 # system time zone.
80 TIME_ZONE = 'UTC'
82 # Language code for this installation. All choices can be found here:
83 # http://www.i18nguy.com/unicode/language-identifiers.html
84 LANGUAGE_CODE = 'en-us'
86 SITE_ID = 1
88 # If you set this to False, Django will make some optimizations so as not
89 # to load the internationalization machinery.
90 USE_I18N = True
92 STATIC_ROOT = 'staticfiles'
93 STATIC_URL = '/media/'
95 STATICFILES_DIRS = (
96 os.path.abspath(os.path.join(BASE_DIR, '..', 'htdocs', 'media')),
99 # List of callables that know how to import templates from various sources.
100 TEMPLATE_LOADERS = (
101 'django.template.loaders.app_directories.Loader',
104 MIDDLEWARE_CLASSES = (
105 'django.middleware.cache.UpdateCacheMiddleware',
106 'django.middleware.common.CommonMiddleware',
107 'django.middleware.csrf.CsrfViewMiddleware',
108 'django.middleware.cache.FetchFromCacheMiddleware',
109 'django.contrib.sessions.middleware.SessionMiddleware',
110 'django.contrib.auth.middleware.AuthenticationMiddleware',
111 'django.middleware.locale.LocaleMiddleware',
112 'django.contrib.messages.middleware.MessageMiddleware',
115 ROOT_URLCONF = 'mygpo.urls'
117 TEMPLATE_DIRS = ()
119 INSTALLED_APPS = (
120 'django.contrib.contenttypes',
121 'django.contrib.messages',
122 'django.contrib.admin',
123 'django.contrib.humanize',
124 'django.contrib.auth',
125 'django.contrib.sessions',
126 'django.contrib.staticfiles',
127 'djcelery',
128 'mygpo.core',
129 'mygpo.podcasts',
130 'mygpo.chapters',
131 'mygpo.search',
132 'mygpo.users',
133 'mygpo.api',
134 'mygpo.web',
135 'mygpo.publisher',
136 'mygpo.subscriptions',
137 'mygpo.history',
138 'mygpo.favorites',
139 'mygpo.data',
140 'mygpo.userfeeds',
141 'mygpo.suggestions',
142 'mygpo.directory',
143 'mygpo.categories',
144 'mygpo.maintenance',
145 'mygpo.share',
146 'mygpo.administration',
147 'mygpo.pubsub',
148 'mygpo.podcastlists',
149 'mygpo.votes',
150 'mygpo.db.couchdb',
153 try:
154 import debug_toolbar
155 INSTALLED_APPS += ('debug_toolbar', )
157 except ImportError:
158 print >> sys.stderr, 'Could not load django-debug-toolbar'
161 TEST_EXCLUDE = (
162 'django',
163 'couchdbkit',
167 TEST_RUNNER = 'mygpo.test.MygpoTestSuiteRunner'
170 ACCOUNT_ACTIVATION_DAYS = parse_int(os.getenv('ACCOUNT_ACTIVATION_DAYS', 7))
173 AUTHENTICATION_BACKENDS = (
174 'django.contrib.auth.backends.ModelBackend',
175 'mygpo.web.auth.EmailAuthenticationBackend',
178 SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
180 # TODO: use (default) JSON serializer for security
181 # this would currently fail as we're (de)serializing datetime objects
182 # https://docs.djangoproject.com/en/1.5/topics/http/sessions/#session-serialization
183 SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
186 from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
188 TEMPLATE_CONTEXT_PROCESSORS += (
189 "mygpo.web.google.analytics",
190 "mygpo.web.google.adsense",
192 # make the debug variable available in templates
193 # https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-debug
194 "django.core.context_processors.debug",
196 # required so that the request obj can be accessed from templates.
197 # this is used to direct users to previous page after login
198 'django.core.context_processors.request',
201 MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
203 USER_CLASS = 'mygpo.users.models.User'
205 LOGIN_URL = '/login/'
207 CSRF_FAILURE_VIEW = 'mygpo.web.views.security.csrf_failure'
210 DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', '')
213 SECRET_KEY = os.getenv('SECRET_KEY', '')
216 GOOGLE_ANALYTICS_PROPERTY_ID = os.getenv('GOOGLE_ANALYTICS_PROPERTY_ID', '')
219 DIRECTORY_EXCLUDED_TAGS = parse_strlist(os.getenv('DIRECTORY_EXCLUDED_TAGS',
220 ''))
223 FLICKR_API_KEY = os.getenv('FLICKR_API_KEY', '')
226 MAINTENANCE = parse_bool(os.getenv('MAINTENANCE', False))
229 LOGGING = {
230 'version': 1,
231 'disable_existing_loggers': True,
232 'formatters': {
233 'verbose': {
234 'format': '%(asctime)s %(name)s %(levelname)s %(message)s',
237 'filters': {
238 'require_debug_false': {
239 '()': 'django.utils.log.RequireDebugFalse'
242 'handlers': {
243 'console':{
244 'level': 'DEBUG',
245 'class': 'logging.StreamHandler',
246 'formatter': 'verbose'
248 'mail_admins': {
249 'level': 'ERROR',
250 'filters': ['require_debug_false'],
251 'class': 'django.utils.log.AdminEmailHandler'
254 'loggers': {
255 'django': {
256 'handlers': ['console'],
257 'propagate': True,
258 'level': 'WARN',
260 'mygpo': {
261 'handlers': ['console'],
262 'level': 'INFO',
264 'celery': {
265 'handlers': ['console'],
266 'level': 'DEBUG',
271 # minimum number of subscribers a podcast must have to be assigned a slug
272 PODCAST_SLUG_SUBSCRIBER_LIMIT = 10
274 # minimum number of subscribers that a podcast needs to "push" one of its
275 # categories to the top
276 MIN_SUBSCRIBERS_CATEGORY=10
278 # maximum number of episode actions that the API processes immediatelly before
279 # returning the response. Larger requests will be handled in background.
280 # Handler can be set to None to disable
281 API_ACTIONS_MAX_NONBG=100
282 API_ACTIONS_BG_HANDLER='mygpo.api.tasks.episode_actions_celery_handler'
285 ADSENSE_CLIENT = ''
286 ADSENSE_SLOT_BOTTOM = ''
288 # enabled access to staff-only areas with ?staff=<STAFF_TOKEN>
289 STAFF_TOKEN = None
291 # Flattr settings -- available after you register your app
292 FLATTR_KEY = ''
293 FLATTR_SECRET = ''
295 # Flattr thing of the webservice. Will be flattr'd when a user sets the "Auto-Flattr gpodder.net" option
296 FLATTR_MYGPO_THING='https://flattr.com/submit/auto?user_id=stefankoegl&url=http://gpodder.net'
298 # The User-Agent string used for outgoing HTTP requests
299 USER_AGENT = 'gpodder.net (+https://github.com/gpodder/mygpo)'
301 # Base URL of the website that is used if the actually used parameters is not
302 # available. Request handlers, for example, can access the requested domain.
303 # Code that runs in background can not do this, and therefore requires a
304 # default value. This should be set to something like 'http://example.com'
305 DEFAULT_BASE_URL = ''
308 ### Celery
310 BROKER_URL='redis://localhost'
311 CELERY_RESULT_BACKEND='redis://localhost'
313 CELERY_SEND_TASK_ERROR_EMAILS = True,
314 ADMINS=ADMINS,
315 SERVER_EMAIL = "no-reply@example.com",
318 ### Google API
320 GOOGLE_CLIENT_ID=''
321 GOOGLE_CLIENT_SECRET=''
323 # URL where users of the site can get support
324 SUPPORT_URL=''
327 # Elasticsearch settings
329 ELASTICSEARCH_SERVER = os.getenv('ELASTICSEARCH_SERVER', '127.0.0.1:9200')
330 ELASTICSEARCH_INDEX = os.getenv('ELASTICSEARCH_INDEX', 'mygpo')
331 ELASTICSEARCH_TIMEOUT = float(os.getenv('ELASTICSEARCH_TIMEOUT', '2'))
333 # time for how long an activation is valid; after that, an unactivated user
334 # will be deleted
335 ACTIVATION_VALID_DAYS = int(os.getenv('ACTIVATION_VALID_DAYS', 10))
337 import sys
338 if 'test' in sys.argv:
339 SECRET_KEY = 'test'
342 INTERNAL_IPS = os.getenv('INTERNAL_IPS', '').split()
344 try:
345 from settings_prod import *
346 except ImportError, e:
347 import sys
348 print >> sys.stderr, 'create settings_prod.py with your customized settings'