Remove unused license preamble
[mygpo.git] / mygpo / settings.py
blob987ae82478802357b02b857f955323efde67a7b1
1 import re
2 import sys
3 import os.path
4 import dj_database_url
7 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
10 def get_bool(name, default):
11 return os.getenv(name, str(default)).lower() == 'true'
14 def get_intOrNone(name, default):
15 """ Parses the env variable, accepts ints and literal None"""
16 value = os.getenv(name, str(default))
17 if value.lower() == 'none':
18 return None
19 return int(value)
22 DEBUG = get_bool('DEBUG', False)
24 ADMINS = re.findall(r'\s*([^<]+) <([^>]+)>\s*', os.getenv('ADMINS', ''))
26 MANAGERS = ADMINS
28 DATABASES = {
29 'default': dj_database_url.config(
30 default='postgres://mygpo:mygpo@localhost/mygpo'),
34 _cache_used = bool(os.getenv('CACHE_BACKEND', False))
36 if _cache_used:
37 CACHES = {}
38 CACHES['default'] = {
39 'BACKEND': os.getenv(
40 'CACHE_BACKEND',
41 'django.core.cache.backends.memcached.MemcachedCache'),
42 'LOCATION': os.getenv('CACHE_LOCATION'),
46 # Local time zone for this installation. Choices can be found here:
47 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
48 # although not all choices may be available on all operating systems.
49 # If running in a Windows environment this must be set to the same as your
50 # system time zone.
51 TIME_ZONE = 'UTC'
53 # Language code for this installation. All choices can be found here:
54 # http://www.i18nguy.com/unicode/language-identifiers.html
55 LANGUAGE_CODE = 'en-us'
57 SITE_ID = 1
59 # If you set this to False, Django will make some optimizations so as not
60 # to load the internationalization machinery.
61 USE_I18N = True
63 STATIC_ROOT = 'staticfiles'
64 STATIC_URL = '/media/'
66 STATICFILES_DIRS = (
67 os.path.abspath(os.path.join(BASE_DIR, '..', 'htdocs', 'media')),
71 TEMPLATES = [{
72 'BACKEND': 'django.template.backends.django.DjangoTemplates',
73 'DIRS': [],
74 'OPTIONS': {
75 'debug': DEBUG,
76 'context_processors': [
77 'django.contrib.auth.context_processors.auth',
78 'django.template.context_processors.debug',
79 'django.template.context_processors.i18n',
80 'django.template.context_processors.media',
81 'django.template.context_processors.static',
82 'django.template.context_processors.tz',
83 'django.contrib.messages.context_processors.messages',
84 'mygpo.web.google.analytics',
85 'mygpo.web.google.adsense',
86 # make the debug variable available in templates
87 # https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-debug
88 'django.core.context_processors.debug',
90 # required so that the request obj can be accessed from
91 # templates. this is used to direct users to previous
92 # page after login
93 'django.core.context_processors.request',
95 'libraries': {
96 'staticfiles' : 'django.templatetags.static',
98 'loaders': [
99 ('django.template.loaders.cached.Loader', [
100 'django.template.loaders.app_directories.Loader',
107 MIDDLEWARE_CLASSES = (
108 'django.middleware.common.CommonMiddleware',
109 'django.middleware.csrf.CsrfViewMiddleware',
110 'django.contrib.sessions.middleware.SessionMiddleware',
111 'django.contrib.auth.middleware.AuthenticationMiddleware',
112 'django.middleware.locale.LocaleMiddleware',
113 'django.contrib.messages.middleware.MessageMiddleware',
116 ROOT_URLCONF = 'mygpo.urls'
118 INSTALLED_APPS = [
119 'django.contrib.contenttypes',
120 'django.contrib.messages',
121 'django.contrib.admin',
122 'django.contrib.humanize',
123 'django.contrib.auth',
124 'django.contrib.sessions',
125 'django.contrib.staticfiles',
126 'django.contrib.sites',
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.usersettings',
140 'mygpo.data',
141 'mygpo.userfeeds',
142 'mygpo.suggestions',
143 'mygpo.directory',
144 'mygpo.categories',
145 'mygpo.episodestates',
146 'mygpo.maintenance',
147 'mygpo.share',
148 'mygpo.administration',
149 'mygpo.pubsub',
150 'mygpo.podcastlists',
151 'mygpo.votes',
152 'django_nose',
155 try:
156 import debug_toolbar
157 INSTALLED_APPS += ['debug_toolbar']
158 MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware', )
160 except ImportError:
161 pass
164 try:
165 import opbeat
167 if not DEBUG:
168 INSTALLED_APPS += ['opbeat.contrib.django']
170 # add opbeat middleware to the beginning of the middleware classes list
171 MIDDLEWARE_CLASSES = \
172 ('opbeat.contrib.django.middleware.OpbeatAPMMiddleware',) + \
173 MIDDLEWARE_CLASSES
175 except ImportError:
176 pass
179 ACCOUNT_ACTIVATION_DAYS = int(os.getenv('ACCOUNT_ACTIVATION_DAYS', 7))
181 AUTHENTICATION_BACKENDS = (
182 'mygpo.users.backend.CaseInsensitiveModelBackend',
183 'mygpo.web.auth.EmailAuthenticationBackend',
186 SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
188 # TODO: use (default) JSON serializer for security
189 # this would currently fail as we're (de)serializing datetime objects
190 # https://docs.djangoproject.com/en/1.5/topics/http/sessions/#session-serialization
191 SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
194 MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
196 USER_CLASS = 'mygpo.users.models.User'
198 LOGIN_URL = '/login/'
200 CSRF_FAILURE_VIEW = 'mygpo.web.views.csrf_failure'
203 DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', '')
205 SECRET_KEY = os.getenv('SECRET_KEY', '')
207 if 'test' in sys.argv:
208 SECRET_KEY = 'test'
210 GOOGLE_ANALYTICS_PROPERTY_ID = os.getenv('GOOGLE_ANALYTICS_PROPERTY_ID', '')
212 DIRECTORY_EXCLUDED_TAGS = os.getenv('DIRECTORY_EXCLUDED_TAGS', '').split()
214 FLICKR_API_KEY = os.getenv('FLICKR_API_KEY', '')
216 SOUNDCLOUD_CONSUMER_KEY = os.getenv('SOUNDCLOUD_CONSUMER_KEY', '')
218 MAINTENANCE = get_bool('MAINTENANCE', False)
221 ALLOWED_HOSTS = ['*']
224 LOGGING = {
225 'version': 1,
226 'disable_existing_loggers': False,
227 'formatters': {
228 'verbose': {
229 'format': '%(asctime)s %(name)s %(levelname)s %(message)s',
232 'filters': {
233 'require_debug_false': {
234 '()': 'django.utils.log.RequireDebugFalse'
237 'handlers': {
238 'console': {
239 'level': os.getenv('LOGGING_CONSOLE_LEVEL', 'DEBUG'),
240 'class': 'logging.StreamHandler',
241 'formatter': 'verbose',
243 'mail_admins': {
244 'level': 'ERROR',
245 'filters': ['require_debug_false'],
246 'class': 'django.utils.log.AdminEmailHandler',
249 'loggers': {
250 'django': {
251 'handlers': os.getenv('LOGGING_DJANGO_HANDLERS',
252 'console').split(),
253 'propagate': True,
254 'level': os.getenv('LOGGING_DJANGO_LEVEL', 'WARN'),
256 'mygpo': {
257 'handlers': os.getenv('LOGGING_MYGPO_HANDLERS', 'console').split(),
258 'level': os.getenv('LOGGING_MYGPO_LEVEL', 'INFO'),
260 'celery': {
261 'handlers': os.getenv('LOGGING_CELERY_HANDLERS',
262 'console').split(),
263 'level': os.getenv('LOGGING_CELERY_LEVEL', 'DEBUG'),
268 _use_log_file = bool(os.getenv('LOGGING_FILENAME', False))
270 if _use_log_file:
271 LOGGING['handlers']['file'] = {
272 'level': 'INFO',
273 'class': 'logging.handlers.RotatingFileHandler',
274 'filename': os.getenv('LOGGING_FILENAME'),
275 'maxBytes': 10000000,
276 'backupCount': 10,
277 'formatter': 'verbose',
281 # minimum number of subscribers a podcast must have to be assigned a slug
282 PODCAST_SLUG_SUBSCRIBER_LIMIT = int(os.getenv(
283 'PODCAST_SLUG_SUBSCRIBER_LIMIT', 10))
285 # minimum number of subscribers that a podcast needs to "push" one of its
286 # categories to the top
287 MIN_SUBSCRIBERS_CATEGORY = int(os.getenv('MIN_SUBSCRIBERS_CATEGORY', 10))
289 # maximum number of episode actions that the API processes immediatelly before
290 # returning the response. Larger requests will be handled in background.
291 # Handler can be set to None to disable
292 API_ACTIONS_MAX_NONBG = int(os.getenv('API_ACTIONS_MAX_NONBG', 100))
293 API_ACTIONS_BG_HANDLER = 'mygpo.api.tasks.episode_actions_celery_handler'
296 ADSENSE_CLIENT = os.getenv('ADSENSE_CLIENT', '')
298 ADSENSE_SLOT_BOTTOM = os.getenv('ADSENSE_SLOT_BOTTOM', '')
300 # we're running behind a proxy that sets the X-Forwarded-Proto header correctly
301 # see https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
302 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
305 # enabled access to staff-only areas with ?staff=<STAFF_TOKEN>
306 STAFF_TOKEN = os.getenv('STAFF_TOKEN', None)
308 # Flattr settings -- available after you register your app
309 FLATTR_KEY = os.getenv('FLATTR_KEY', '')
310 FLATTR_SECRET = os.getenv('FLATTR_SECRET', '')
312 # Flattr thing of the webservice. Will be flattr'd when a user sets
313 # the "Auto-Flattr gpodder.net" option
314 FLATTR_MYGPO_THING = os.getenv(
315 'FLATTR_MYGPO_THING',
316 'https://flattr.com/submit/auto?user_id=stefankoegl&url=http://gpodder.net'
319 # The User-Agent string used for outgoing HTTP requests
320 USER_AGENT = 'gpodder.net (+https://github.com/gpodder/mygpo)'
322 # Base URL of the website that is used if the actually used parameters is not
323 # available. Request handlers, for example, can access the requested domain.
324 # Code that runs in background can not do this, and therefore requires a
325 # default value. This should be set to something like 'http://example.com'
326 DEFAULT_BASE_URL = os.getenv('DEFAULT_BASE_URL', '')
329 ### Celery
331 BROKER_URL = os.getenv('BROKER_URL', 'redis://localhost')
332 CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
334 SERVER_EMAIL = os.getenv('SERVER_EMAIL', 'no-reply@example.com')
336 CELERY_TASK_RESULT_EXPIRES = 60 * 60 # 1h expiry time in seconds
338 CELERY_ACCEPT_CONTENT = ['pickle', 'json']
340 CELERY_SEND_TASK_ERROR_EMAILS = get_bool('CELERY_SEND_TASK_ERROR_EMAILS',
341 False)
343 BROKER_POOL_LIMIT = get_intOrNone('BROKER_POOL_LIMIT', 10)
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')
379 PODCAST_AD_ID = os.getenv('PODCAST_AD_ID')
381 TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
383 NOSE_ARGS = [
384 '--with-doctest',
385 '--stop',
386 '--where=mygpo',