From 0d4e95f42de9db36bfde4e52d33a7cbbf0b50402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Sat, 18 Jul 2015 13:38:50 -0400 Subject: [PATCH] add compatibilty for mimetype on HttpResponse --- chatrooms/ajax/chat.py | 2 +- chatrooms/utils/compat.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 chatrooms/utils/compat.py diff --git a/chatrooms/ajax/chat.py b/chatrooms/ajax/chat.py index fbfdcf9..2aed5cc 100644 --- a/chatrooms/ajax/chat.py +++ b/chatrooms/ajax/chat.py @@ -8,7 +8,7 @@ from django.conf import settings from django.db.models.signals import post_save from django.dispatch import receiver -from django.http import (HttpResponse, +from ..utils.compat import (HttpResponse, HttpResponseBadRequest) from django.utils.decorators import method_decorator diff --git a/chatrooms/utils/compat.py b/chatrooms/utils/compat.py new file mode 100644 index 0000000..baeb965 --- /dev/null +++ b/chatrooms/utils/compat.py @@ -0,0 +1,18 @@ +from django import VERSION +from django.http import (HttpResponse as BaseHttpResponse, + HttpResponseBadRequest as Base400) + +# https://github.com/chicagobuss/graphite-web/commit/842944a34085c4b6bd5f37532118be996a0ff4f1 +class ContentTypeMixin(object): + def __init__(self, *args, **kwargs): + if VERSION < (1, 5) and 'content_type' in kwargs: + kwargs['mimetype'] = kwargs.pop('content_type') + elif VERSION > (1, 7) and 'mimetype' in kwargs: + kwargs['content_type'] = kwargs.pop('mimetype') + super(ContentTypeMixin, self).__init__(*args, **kwargs) + +class HttpResponse(ContentTypeMixin, BaseHttpResponse): + pass + +class HttpResponseBadRequest(ContentTypeMixin, Base400): + pass