Commits

Bruno Renié committed dc52c22

Env-based settings, discovery runner and logging/sentry handling

Comments (0)

Files changed (5)

 	foreman start
 
 test:
-	django-admin.py test ${ARGS} $(test_settings) --failfast
+	django-admin.py test $(test_settings) --failfast
 
 debugtest:
-	django-admin.py test ${ARGS} $(test_settings) -v2
+	django-admin.py test $(test_settings) -v2

dotim/blog/templatetags/colorful.py

         pass
 
     def render(self, context):
-        chunks = bitify(settings.DOTIM_TITLE[0])
+        chunks = bitify(settings.DOTIM_TITLE)
         rendered = ''
         for (text, color) in chunks:
             rendered += '<span style="color: #%s;">%s</span>' % (color, text)

dotim/context_processors.py

 def dotim(request):
     """Returns a set of values under the ``dotim`` namespace"""
     return {'dotim': {
-        'head_title': settings.DOTIM_TITLE[1],
+        'head_title': settings.DOTIM_TITLE.lower(),
     }}

dotim/default_settings.py

+import dj_database_url
 import os
+import urlparse
+
 HERE = os.path.abspath(os.path.dirname(__file__))
 
-DEBUG = False
+DEBUG = bool(os.environ.get('DEBUG', False))
 TEMPLATE_DEBUG = DEBUG
 
-ADMINS = ()
-MANAGERS = ADMINS
+DATABASES = {'default': dj_database_url.config()}
 
 TIME_ZONE = 'Europe/Paris'
 
 SITE_ID = 1
 
 USE_I18N = True
+USE_L10N = True
 
-MEDIA_ROOT = os.path.join(HERE, 'media')
+MEDIA_ROOT = os.environ.get('MEDIA_ROOT', os.path.join(HERE, 'media'))
 MEDIA_URL = '/media/'
 
-STATIC_ROOT = os.path.join(HERE, 'static')
+STATIC_ROOT = os.environ.get('STATIC_ROOT', os.path.join(HERE, 'static'))
 STATIC_URL = '/static/'
 
-STATICFILES_STORAGE = ('django.contrib.staticfiles.storage'
-                       '.CachedStaticFilesStorage')
+if not DEBUG:
+    STATICFILES_STORAGE = ('django.contrib.staticfiles.storage'
+                           '.CachedStaticFilesStorage')
 
-TEMPLATE_LOADERS = (
-    ('django.template.loaders.cached.Loader', (
+if DEBUG:
+    TEMPLATE_LOADERS = (
         'django.template.loaders.filesystem.Loader',
         'django.template.loaders.app_directories.Loader',
-    )),
-)
+    )
+else:
+    TEMPLATE_LOADERS = (
+        ('django.template.loaders.cached.Loader', (
+            'django.template.loaders.filesystem.Loader',
+            'django.template.loaders.app_directories.Loader',
+        )),
+    )
 
 TEMPLATE_CONTEXT_PROCESSORS = (
     'django.contrib.auth.context_processors.auth',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
 )
 
 ROOT_URLCONF = 'dotim.urls'
     'dotim.projects',
 )
 
+if 'SENTRY_DSN' in os.environ:
+    INSTALLED_APPS += (
+        'raven.contrib.django',
+    )
+
+if 'REDIS_URL' in os.environ:
+    parsed_redis = urlparse.urlparse(os.environ['REDIS_URL'])
+    CACHES = {
+        'default': {
+            'BACKEND': 'redis_cache.RedisCache',
+            'LOCATION': parsed_redis.netloc,
+            'OPTIONS': {
+                'DB': int(parsed_redis.path[1:]),
+            },
+        },
+    }
+    MESSAGE_STORAGE = ('django.contrib.messages.storage.'
+                       'fallback.FallbackStorage')
+    SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
+
 DATE_FORMAT = 'F j, Y'
 
 THUMBNAIL_QUALITY = 100
 
-DOTIM_TITLE = (
-    "Bruno.im",
-    "bruno.im",
-)
+DOTIM_TITLE = os.environ.get("DOTIM_TITLE", "Bruno.im")
+
+TEST_RUNNER = 'discover_runner.runner.DiscoverRunner'
+TEST_DISCOVER_TOP_LEVEL = os.path.join(HERE, os.pardir)
+TEST_DISCOVER_ROOT = os.path.join(TEST_DISCOVER_TOP_LEVEL, 'dotim')
+
+LOGGING = {
+    'version': 1,
+    'disable_existing_loggers': False,
+    'formatters': {
+        'simple': {
+            'format': '%(asctime)s %(levelname)s: %(message)s'
+        },
+    },
+    'handlers': {
+        'console': {
+            'level': 'DEBUG',
+            'class': 'logging.StreamHandler',
+            'formatter': 'simple',
+        },
+        'sentry': {
+            'level': 'INFO',
+            'class': 'raven.contrib.django.handlers.SentryHandler',
+        },
+    },
+    'loggers': {
+        'django.request': {
+            'handlers': ['console'],
+            'level': 'ERROR',
+            'propagate': True,
+        },
+        'dotim': {
+            'handlers': ['console', 'sentry'],
+            'level': 'DEBUG',
+        },
+        'raven': {
+            'handlers': ['console'],
+            'level': 'DEBUG',
+            'propagate': False,
+        },
+        'sentry.errors': {
+            'handlers': ['console'],
+            'level': 'DEBUG',
+            'propagate': False,
+        },
+    }
+}
 Pygments==1.5
 akismet==0.2.0
 dj-database-url==0.2.1
+django-discover-runner==0.2.2
 django-tagging==0.3.1
 docutils==0.9.1
 easy-thumbnails==1.1
 mock==1.0.0
 psycopg2==2.4.5
 python-dateutil==2.1
+raven==2.0.7.1
 requests==0.14.2
+simplejson==2.6.2
 six==1.2.0