diff --git a/opentech/settings/base.py b/opentech/settings/base.py index 98ff20a50b15ab823831c9de4eadb23a40f3c043..7f96ff6c85a8096867434d24c9b350f848d8333a 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -375,6 +375,7 @@ ESI_ENABLED = False # Custom settings ENABLE_STYLEGUIDE = False +DEBUGTOOLBAR = False # Social Auth SOCIAL_AUTH_URL_NAMESPACE = 'social' diff --git a/opentech/settings/dev.py b/opentech/settings/dev.py index b6277f0661144779c4d316f69c257a2e8844d341..176f00d6dc4033024cd9f363b2bb28663575f326 100644 --- a/opentech/settings/dev.py +++ b/opentech/settings/dev.py @@ -22,7 +22,90 @@ INSTALLED_APPS = INSTALLED_APPS + [ SECURE_SSL_REDIRECT = False +# Change these in local.py. +LOCAL_FILE_LOGGING = False +LOCAL_FILE_EMAIL = False + try: from .local import * # noqa except ImportError: pass + +# We add these here so they can react on settings made in local.py. + +# E-mail to local files. +if LOCAL_FILE_EMAIL: + EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend' + EMAIL_FILE_PATH = BASE_DIR + '/var/mail' + +# Local logging to file. +if LOCAL_FILE_LOGGING: + LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'formatters': { + 'standard': { + 'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s", + 'datefmt': "%Y-%m-%d %H:%M:%S" + }, + }, + 'handlers': { + 'null': { + 'level': 'DEBUG', + 'class': 'logging.NullHandler', + }, + 'logfile': { + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', + 'filename': BASE_DIR + '/var/log/debug.log', + 'maxBytes': 1000000, + 'backupCount': 2, + 'formatter': 'standard', + }, + }, + 'loggers': { + 'django': { + 'handlers': ['logfile'], + 'level': 'INFO', + 'propagate': True, + }, + 'django.db.backends': { + 'handlers': ['logfile'], + 'level': 'INFO', + 'propagate': False, + }, + 'django.request': { + 'handlers': ['logfile'], + 'level': 'DEBUG', + 'propagate': False, + }, + 'django.template': { + 'handlers': ['logfile'], + 'level': 'INFO', + 'propagate': False, + }, + 'django.security': { + 'handlers': ['logfile'], + 'level': 'DEBUG', + 'propagate': False, + }, + 'wagtail': { + 'handlers': ['logfile'], + 'level': 'DEBUG', + }, + 'opentech': { + 'handlers': ['logfile'], + 'level': 'DEBUG', + }, + } + } + +# Set up the Django debug toolbar. See also root urls.py. +if DEBUGTOOLBAR: + INSTALLED_APPS += [ + 'debug_toolbar', + ] + + MIDDLEWARE = [ + 'debug_toolbar.middleware.DebugToolbarMiddleware', + ] + MIDDLEWARE diff --git a/opentech/settings/local.py.example b/opentech/settings/local.py.example index f6a9344edbddfef974cc77d745fd7a49a2f53158..f9ae5091dbea8695bf7ddd5de87ad8c2ae7986e6 100644 --- a/opentech/settings/local.py.example +++ b/opentech/settings/local.py.example @@ -4,10 +4,21 @@ CACHES = { } } +# Use the Django debug toolbar. First install via pip. +# pip install django-debug-toolbar +# DEBUGTOOLBAR = True + +# Write log to local file. +# LOCAL_FILE_LOGGING = True + +# Write e-mails to local files. +# LOCAL_FILE_EMAIL = True + # On staging, uncomment the following to enable the styleguide # ENABLE_STYLEGUIDE = True -# DO NOT use on production -RECAPTCHA_PUBLIC_KEY = '6LelrggUAAAAANL1b4NcQpJxjgoWQEugpoGqeq2q' -RECAPTCHA_PRIVATE_KEY = '6LelrggUAAAAAD2gDgs43P9NSa9ScvkU6ZmBAW_F' -NOCAPTCHA = True +# ALLOWED_HOSTS = ['apply.otf.test', 'otf.test', '127.0.0.1'] + +# BASE_URL = 'http://otf.test' + +# SECRET_KEY = 'CHANGEME!!!' diff --git a/opentech/urls.py b/opentech/urls.py index 6ccf53e45e08630bc26257b714c8b501746210f4..8cb2fe3067cbc3bd1c7e042adb4d2243ae8c6b07 100644 --- a/opentech/urls.py +++ b/opentech/urls.py @@ -61,3 +61,9 @@ if cache_length: urlpatterns, cache_control(max_age=cache_length) ) + +if settings.DEBUG and settings.DEBUGTOOLBAR: + import debug_toolbar + urlpatterns = [ + path('__debug__/', include(debug_toolbar.urls)), + ] + urlpatterns