aboutsummaryrefslogtreecommitdiff
path: root/settings.py
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2015-04-01 11:05:10 -0500
committerAndy Doan <andy.doan@linaro.org>2015-04-01 14:03:10 -0500
commit17bc210a625496a67c4d58cc40b2d309e5e4670c (patch)
treed614341bc31ce3093c2a71bbbe931405b8214b03 /settings.py
parent8efbf7eb6e90616d62a5371272790884e5874038 (diff)
stop sending email for ALLOWED_HOSTS violations
There's a proper fix in django >= 1.6, but we have to do some hacking for our 1.3.7 version used on our precise servers (releases and snapshots) Change-Id: I4b62f457511aa41248f484e147a167604a140507
Diffstat (limited to 'settings.py')
-rw-r--r--settings.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/settings.py b/settings.py
index 00a36ce..b10d268 100644
--- a/settings.py
+++ b/settings.py
@@ -185,6 +185,31 @@ LOGGING = {
}
}
+import django
+if django.VERSION < (1, 6):
+ # old django needs a hack to not send emails for ALLOWED_HOSTS violations
+ from django.core.exceptions import SuspiciousOperation
+
+ class SuspiciousFilter(object):
+ def filter(self, record):
+ if record.exc_info:
+ exc_type, exc_value = record.exc_info[:2]
+ if isinstance(exc_value, SuspiciousOperation):
+ return False
+ return True
+
+ LOGGING['handlers']['mail_admins']['filters'] = ['skip_suspicious']
+ LOGGING['filters'] = {
+ 'skip_suspicious': {'()': SuspiciousFilter}
+ }
+else:
+ # don't send email for ALLOWED_HOSTS violations
+ LOGGING['loggers']['django.security.DisallowedHost'] = {
+ 'handlers': ['mail_admins'],
+ 'level': 'CRITICAL',
+ 'propagate': False,
+ }
+
SERVED_PATHS = [os.path.join(PROJECT_ROOT, "sampleroot")]
UPLOAD_PATH = os.path.join(PROJECT_ROOT, "sample_upload_root")